root/lang/perl/Const/trunk/t/03-obj.t @ 14680

Revision 14680, 0.6 kB (checked in by dankogai, 6 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#
5use strict;
6use warnings;
7use Const;
8#use Test::More 'no_plan';
9use 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
30ARRAY
31HASH
32#CODE
33#REF
34#GLOB
35#LVALUE
36#FORMAT
37#IO
38#VSTRING
39#Regexp
40
Note: See TracBrowser for help on using the browser.