Begin adding Squirrel::Role
Shawn M Moore [Tue, 17 Jun 2008 04:16:47 +0000 (04:16 +0000)]
lib/Squirrel/Role.pm [new file with mode: 0644]

diff --git a/lib/Squirrel/Role.pm b/lib/Squirrel/Role.pm
new file mode 100644 (file)
index 0000000..dfcb2e5
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/perl
+
+package Squirrel::Role;
+
+use strict;
+use warnings;
+
+sub _choose_backend {
+    if ( $INC{"Moose/Role.pm"} ) {
+        return {
+            import   => \&Moose::Role::import,
+            unimport => \&Moose::Role::unimport,
+        }
+    } else {
+        require Mouse::Role;
+        return {
+            import   => \&Mouse::Role::import,
+            unimport => \&Mouse::Role::unimport,
+        }
+    }
+}
+
+my %pkgs;
+
+sub _handlers {
+    my $class = shift;
+
+    my $caller = caller(1);
+
+    $pkgs{$caller} = $class->_choose_backend
+        unless $pkgs{$caller};
+}
+
+sub import {
+    goto $_[0]->_handlers->{import};
+}
+
+sub unimport {
+    goto $_[0]->_handlers->{unimport};
+}
+
+1;
+