Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: shelling/namespace-dispatch
base: 8d1ec86434
...
head fork: shelling/namespace-dispatch
compare: 2e35568827
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 10, 2013
@shelling shorter code 89b9889
@shelling support Class and Role in Moose fd2ec86
@shelling ignore MYMETA.* dfbd495
@shelling Checking in changes prior to tagging of version 0.05.
Changelog diff is:

diff --git a/Changes b/Changes
index c96ee19..e952c73 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension Namespace::Dispatch

+0.05    Thu Jan 10 18:18:39 CST 2013
+        - support Class and Role in Moose
+
 0.04    Sun Jul 15 15:34.21 2012
         - move subroutines out of import()
2e35568
View
1  .gitignore
@@ -10,3 +10,4 @@ nytprof.out
MANIFEST.bak
*.sw[po]
*.tar.gz
+MYMETA.*
View
3  Changes
@@ -1,5 +1,8 @@
Revision history for Perl extension Namespace::Dispatch
+0.05 Thu Jan 10 18:18:39 CST 2013
+ - support Class and Role in Moose
+
0.04 Sun Jul 15 15:34.21 2012
- move subroutines out of import()
View
22 lib/Namespace/Dispatch.pm
@@ -1,17 +1,25 @@
package Namespace::Dispatch;
-our $VERSION = '0.04';
+our $VERSION = '0.05';
use 5.010;
use UNIVERSAL::filename;
sub import {
+ my $pkg = shift;
my $caller = caller;
-
- *{$caller . "::" . "has_leaf"} = *{has_leaf};
-
- *{$caller . "::" . "dispatch"} = *{dispatch};
-
- *{$caller . '::' . 'leaves'} = *{leaves};
+ my $meta = ref($caller->meta) if $caller->can("meta");
+
+ if ( $meta && $meta =~ m/(Class$|Role$)/ ) {
+ eval qq{
+ package $pkg;
+ use Moose::Role;
+ };
+ Moose::Util::apply_all_roles($caller, $pkg, {-excludes => "import"});
+ } else {
+ for (qw(has_leaf dispatch leaves)) {
+ *{$caller . "::" . $_} = *{$_};
+ }
+ }
}
View
2  t/01_simple.t
@@ -10,7 +10,7 @@ use Foo;
is_deeply (
Foo->leaves,
- [qw(add del help modify)],
+ [qw(add class classwithrole del help modify role)],
"Foo has two submodules Add and Del",
);
View
30 t/02_role.t
@@ -0,0 +1,30 @@
+use Modern::Perl;
+use Test::More;
+use Try::Tiny;
+
+use lib qw(lib t/lib);
+use Foo::Class;
+use Foo::ClassWithRole;
+
+is (
+ ref(Namespace::Dispatch->meta),
+ "Moose::Meta::Role",
+ "Namespace::Dispatch is a Moose::Role",
+);
+
+ok (
+ Foo::Class->does("Namespace::Dispatch"),
+ "Foo::Class does Namespace::Dispatch",
+);
+
+ok (
+ Foo::Role->meta->does_role("Namespace::Dispatch"),
+ "Foo::Role does Namespace::Dispatch",
+);
+
+ok (
+ Foo::ClassWithRole->does("Namespace::Dispatch"),
+ "Foo::ClassWithRole does Namespace::Dispatch",
+);
+
+done_testing;
View
4 t/lib/Foo/Class.pm
@@ -0,0 +1,4 @@
+package Foo::Class;
+use Moose;
+use Namespace::Dispatch;
+1;
View
4 t/lib/Foo/ClassWithRole.pm
@@ -0,0 +1,4 @@
+package Foo::ClassWithRole;
+use Moose;
+with qw(Foo::Role);
+1;
View
4 t/lib/Foo/Role.pm
@@ -0,0 +1,4 @@
+package Foo::Role;
+use Moose::Role;
+use Namespace::Dispatch;
+1;

No commit comments for this range

Something went wrong with that request. Please try again.