Help for this page

Select Code to Download


  1. or download this
    my $obj = ClosureObj->new();
    isa_ok( $obj => 'ClosureObj' );
    
  2. or download this
    eval { $obj->('foo') };
    ok( $@ =~ /^Attempt to access private class data/,
            "Stop from accessing class data" );
    
  3. or download this
    eval { $obj->foop() };
    ok( $@ =~ /^No such field/, "Stop from accessing non-existant data" );
    
  4. or download this
    $obj->foo(3);
    ok( $obj->foo == 3, "Foo is set" );
    
  5. or download this
    {
        no warnings; # About unintitlized vars
    ...
        ok( $obj->foo == undef, "Foo can be set to undef" );
    }
    
  6. 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" );
    
  7. 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" );
    
  8. or download this
    sub new
    {
    ...
                    $field{$name};
            } => $class;
    }
    
  9. or download this
    {
            my %fields = ( . . . );
    ...
                    } => $class;
            }
    }
    
  10. or download this
    sub foo
    {
    ...
            $self->('foop', shift) if @_;
            $self->('foop');
    }
    
  11. or download this
    package SubClosureObj;
    use base qw( ClosureObj );
    ...
            $self->('bar', shift) if @_;
            $self->('bar');
    }
    
  12. or download this
    #!/usr/bin/perl
    
    ...
    $sub_obj->bar(4);
    ok( $sub_obj->bar == 4, "Sub object can set values" );