Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

May Thy Closures Be Blessed

by hardburn (Abbot)
on Apr 26, 2004 at 14:50 UTC ( [id://348189]=perlmeditation: print w/replies, xml ) Need Help??

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" );
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://348189]
Approved by broquaint
Front-paged by jdtoronto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-24 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found