From: Matt S Trout Date: Sat, 13 Nov 2010 20:22:43 +0000 (+0000) Subject: _load_module X-Git-Tag: 0.009001~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fb5074f642700cbf0ebed591d9eb3d186ef6f198;p=gitmo%2FRole-Tiny.git _load_module --- diff --git a/lib/Moo.pm b/lib/Moo.pm index 31727fe..f64067b 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -10,6 +10,7 @@ sub import { my $class = shift; strictures->import; *{_getglob("${target}::extends")} = sub { + _load_module($_) for @_; *{_getglob("${target}::ISA")} = \@_; }; *{_getglob("${target}::with")} = sub { diff --git a/lib/Moo/_Utils.pm b/lib/Moo/_Utils.pm index c8549e8..ad0b5b1 100644 --- a/lib/Moo/_Utils.pm +++ b/lib/Moo/_Utils.pm @@ -3,7 +3,7 @@ package Moo::_Utils; use strictures 1; use base qw(Exporter); -our @EXPORT = qw(_getglob _install_modifier _maybe_load_module); +our @EXPORT = qw(_getglob _install_modifier _load_module _maybe_load_module); sub _getglob { no strict 'refs'; \*{$_[0]} } @@ -20,6 +20,13 @@ sub _install_modifier { our %MAYBE_LOADED; +sub _load_module { + return 1 if $_[0]->can('can'); + (my $proto = $_[0]) =~ s/::/\//g; + require "${proto}.pm"; + return 1; +} + sub _maybe_load_module { return $MAYBE_LOADED{$_[0]} if exists $MAYBE_LOADED{$_[0]}; (my $proto = $_[0]) =~ s/::/\//g; diff --git a/lib/Role/Tiny.pm b/lib/Role/Tiny.pm index ee75997..1a4cf9c 100644 --- a/lib/Role/Tiny.pm +++ b/lib/Role/Tiny.pm @@ -9,6 +9,13 @@ our %COMPOSED; sub _getglob { no strict 'refs'; \*{$_[0]} } +sub _load_module { + return 1 if $_[0]->can('can'); + (my $proto = $_[0]) =~ s/::/\//g; + require "${proto}.pm"; + return 1; +} + sub import { my $target = caller; my $me = $_[0]; @@ -43,6 +50,8 @@ sub import { sub apply_role_to_package { my ($me, $role, $to) = @_; + _load_module($role); + die "This is apply_role_to_package" if ref($to); die "${role} is not a Role::Tiny" unless my $info = $INFO{$role}; @@ -72,10 +81,13 @@ sub apply_roles_to_object { sub create_class_with_roles { my ($me, $superclass, @roles) = @_; + die "No roles supplied!" unless @roles; + my $new_name = join('+', $superclass, my $compose_name = join '+', @roles); return $new_name if $COMPOSED{class}{$new_name}; foreach my $role (@roles) { + _load_module($role); die "${role} is not a Role::Tiny" unless my $info = $INFO{$role}; }