Created
April 8, 2014 16:42
-
-
Save yanick/10153724 to your computer and use it in GitHub Desktop.
automoo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use 5.10.0; | |
| sub create_moo { | |
| my ( $class, $prototype ) = @_; | |
| eval join "\n", "package $class;", 'use Moo;', | |
| map { "has $_ => ( is => 'ro' );" } keys %$prototype; | |
| return $class; | |
| } | |
| my %test = ( a => 1, b => 2, c => 3 ); | |
| my $obj = create_moo( 'Stuff', \%test )->new( %test ); | |
| say $obj->c; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to remember a way of modifying the current namespace outside of doing
eval "package $foo;", and I don't come up with anything...