Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

May Thy Closures Be Blessed

by hardburn (Abbot)
on Apr 26, 2004 at 14:50 UTC ( #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
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? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2020-02-28 19:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (127 votes). Check out past polls.

    Notices?