[ create a new paste ] login | about

Link: http://codepad.org/ZBfZ1c7p    [ raw code | output | fork ]

Perl, pasted on Jul 12:
#!perl
use strict;
use warnings;
{
    package Class;
    sub new { 
        my $pkg = shift; 
        bless {@_}, $pkg
    }
    sub property {
        my $self = shift;
        return $self->{property} unless @_;
        $self->{property} = shift;
    }
}
{
    package Closure;
    sub new{
        my $instance = { @_ };
        return sub{
            my $property = shift;
            return $instance->{$property} unless @_;
            $instance->{$property} = shift;
        }
    }
}

{
    my $o = Class->new;
    $o->property('dan');
    warn $o->property;
    my $c = Closure::new;
    $c->(property => 'kogai');
    warn $c->('property');
}


Output:
1
2
dan at t.pl line 31.
kogai at t.pl line 34.


Create a new paste based on this one


Comments: