Skip to content

Instantly share code, notes, and snippets.

@dams
Created September 12, 2011 21:30
Show Gist options
  • Save dams/1212507 to your computer and use it in GitHub Desktop.
Save dams/1212507 to your computer and use it in GitHub Desktop.
different approach
sub Mo'import {
import warnings; $^H |= 0x602;
my $p = caller."'";
@_ = ( ISA, extends, has, sub {
my ( $n, %a ) = @_;
my $d = $a{default}||$a{builder};
*{ $p . $n } = $d
? sub {
$#_ ? $_[0]{$n} = $_[1]
: exists $_[0]{$n} ? $_[0]{$n}
: ( $_[0]{$n} = $_[0]->$d )
}
: sub { $#_ ? $_[0]{$n} = $_[1] : $_[0]{$n} }
}, sub { @{ $p . ISA } = $_[0]; eval "no $_[0] ()" }, [Mo'_]);
*{ $p.$_ } = pop for @_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment