|
Revision 14680, 0.6 kB
(checked in by dankogai, 5 years ago)
|
|
Const - Facility for creating read-only variables
|
| Line | |
|---|
| 1 | #!perl -T |
|---|
| 2 | # |
|---|
| 3 | # $Id: 03-obj.t,v 0.1 2008/06/26 22:26:16 dankogai Exp $ |
|---|
| 4 | # |
|---|
| 5 | use strict; |
|---|
| 6 | use warnings; |
|---|
| 7 | use Const; |
|---|
| 8 | #use Test::More 'no_plan'; |
|---|
| 9 | use Test::More tests => 5; |
|---|
| 10 | |
|---|
| 11 | { |
|---|
| 12 | package Foo; |
|---|
| 13 | sub new { my $pkg = shift; bless { @_ }, $pkg } |
|---|
| 14 | sub get { $_[0]->{foo} } |
|---|
| 15 | sub set { $_[0]->{foo} = $_[1] }; |
|---|
| 16 | } |
|---|
| 17 | { |
|---|
| 18 | Const my $o => Foo->new(foo=>1); |
|---|
| 19 | isa_ok $o, 'Foo'; |
|---|
| 20 | is $o->get, 1, '$o->get == 1'; |
|---|
| 21 | eval{ $o = Foo->new(foo=>2) }; |
|---|
| 22 | ok $@, $@; |
|---|
| 23 | eval{ $o->set(2) }; |
|---|
| 24 | ok !$@, '$o->set(2)'; |
|---|
| 25 | is $o->get, 2, '$o->get == 2'; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | __END__ |
|---|
| 29 | #SCALAR |
|---|
| 30 | ARRAY |
|---|
| 31 | HASH |
|---|
| 32 | #CODE |
|---|
| 33 | #REF |
|---|
| 34 | #GLOB |
|---|
| 35 | #LVALUE |
|---|
| 36 | #FORMAT |
|---|
| 37 | #IO |
|---|
| 38 | #VSTRING |
|---|
| 39 | #Regexp |
|---|
| 40 | |
|---|