Skip to content

Instantly share code, notes, and snippets.

@dr-kd
Created September 22, 2015 23:54
Show Gist options
  • Select an option

  • Save dr-kd/c1fe78828b92081c3f61 to your computer and use it in GitHub Desktop.

Select an option

Save dr-kd/c1fe78828b92081c3f61 to your computer and use it in GitHub Desktop.
#!/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