From: Matt S Trout Date: Tue, 16 Nov 2010 00:17:04 +0000 (+0000) Subject: make role application interface consistent X-Git-Tag: 0.009001~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMoo.git;a=commitdiff_plain;h=369a4c50415c4811e584a11b1201830a11ea1386 make role application interface consistent --- diff --git a/lib/Moo.pm b/lib/Moo.pm index 28e91a8..0ec27a7 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -20,7 +20,7 @@ sub import { *{_getglob("${target}::with")} = sub { require Moo::Role; die "Only one role supported at a time by with" if @_ > 1; - Moo::Role->apply_role_to_package($_[0], $target); + Moo::Role->apply_role_to_package($target, $_[0]); }; $MAKERS{$target} = {}; *{_getglob("${target}::has")} = sub { diff --git a/lib/Moo/Role.pm b/lib/Moo/Role.pm index a8af3cf..6710384 100644 --- a/lib/Moo/Role.pm +++ b/lib/Moo/Role.pm @@ -26,8 +26,8 @@ sub import { } sub apply_role_to_package { - my ($me, $role, $to) = @_; - $me->SUPER::apply_role_to_package($role, $to); + my ($me, $to, $role) = @_; + $me->SUPER::apply_role_to_package($to, $role); $me->_handle_constructor($to, $INFO{$role}{attributes}); } diff --git a/lib/Role/Tiny.pm b/lib/Role/Tiny.pm index 534db17..009814b 100644 --- a/lib/Role/Tiny.pm +++ b/lib/Role/Tiny.pm @@ -35,7 +35,7 @@ sub import { }; *{_getglob "${target}::with"} = sub { die "Only one role supported at a time by with" if @_ > 1; - $me->apply_role_to_package($_[0], $target); + $me->apply_role_to_package($target, $_[0]); }; # grab all *non-constant* (ref eq 'SCALAR') subs present # in the symbol table and store their refaddrs (no need to forcibly @@ -49,7 +49,7 @@ sub import { } sub apply_role_to_package { - my ($me, $role, $to) = @_; + my ($me, $to, $role) = @_; _load_module($role); @@ -279,7 +279,7 @@ is to be much simpler, hence disallowing composition of multiple roles at once. =head2 apply_role_to_package - Role::Tiny->apply_role_to_package('Some::Role', 'Some::Package'); + Role::Tiny->apply_role_to_package('Some::Package', 'Some::Role'); Composes role with package diff --git a/t/role-tiny.t b/t/role-tiny.t index b3ee22f..254e62b 100644 --- a/t/role-tiny.t +++ b/t/role-tiny.t @@ -51,7 +51,7 @@ BEGIN { sub try_apply_to { my $to = shift; - exception { Role::Tiny->apply_role_to_package('MyRole', $to) } + exception { Role::Tiny->apply_role_to_package($to, 'MyRole') } } is(try_apply_to('MyClass'), undef, 'role applies cleanly');