- or download this
my $obj = ClosureObj->new();
isa_ok( $obj => 'ClosureObj' );
- or download this
eval { $obj->('foo') };
ok( $@ =~ /^Attempt to access private class data/,
"Stop from accessing class data" );
- or download this
eval { $obj->foop() };
ok( $@ =~ /^No such field/, "Stop from accessing non-existant data" );
- or download this
$obj->foo(3);
ok( $obj->foo == 3, "Foo is set" );
- or download this
{
no warnings; # About unintitlized vars
...
ok( $obj->foo == undef, "Foo can be set to undef" );
}
- or download this
my $obj2 = ClosureObj->new();
isa_ok( $obj2 => 'ClosureObj' );
...
ok( ($obj->foo == 2) && ($obj2->foo == 3),
"Change in one object doesn't affect other" );
- or download this
my $sub_obj = SubClosureObj->new();
isa_ok( $sub_obj => 'SubClosureObj' );
...
$sub_obj->bar(4);
ok( $sub_obj->bar == 4, "Sub object can set values" );
- or download this
sub new
{
...
$field{$name};
} => $class;
}
- or download this
{
my %fields = ( . . . );
...
} => $class;
}
}
- or download this
sub foo
{
...
$self->('foop', shift) if @_;
$self->('foop');
}
- or download this
package SubClosureObj;
use base qw( ClosureObj );
...
$self->('bar', shift) if @_;
$self->('bar');
}
- or download this
#!/usr/bin/perl
...
$sub_obj->bar(4);
ok( $sub_obj->bar == 4, "Sub object can set values" );