Created
September 22, 2015 23:54
-
-
Save dr-kd/c1fe78828b92081c3f61 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/perl | |
| package Constructor; | |
| use Moose; | |
| with 'MooseX::Traits'; | |
| use namespace::autoclean; | |
| has '+_trait_namespace' => ( default => __PACKAGE__); | |
| sub load { | |
| my ($class, @plugin) = @_; | |
| my $obj_with_plugin = $class->new_with_traits(traits => [@plugin]); | |
| return $obj_with_plugin; | |
| } | |
| __PACKAGE__->meta->make_immutable; | |
| 1; | |
| package Constructor::Plugin; | |
| use Moose::Role; | |
| requires 'frobnicate'; | |
| 1; | |
| package Constructor::Plugin::Component; | |
| use Moose::Role; | |
| sub frobnicate { "zark!\n" } | |
| 1; | |
| package main; | |
| use Test::More; | |
| use Test::Exception; | |
| my $thing; | |
| lives_ok {$thing = Constructor->load('Plugin', 'Plugin::Component')} "instantiated ok"; | |
| ok $thing->frobnicate, "frobnicates ok"; | |
| done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment