From: Shawn M Moore Date: Tue, 17 Jun 2008 04:16:47 +0000 (+0000) Subject: Begin adding Squirrel::Role X-Git-Tag: 0.19~293 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ce2ee568de5a564efc471dcdfa48868e5ca4487b;p=gitmo%2FMouse.git Begin adding Squirrel::Role --- diff --git a/lib/Squirrel/Role.pm b/lib/Squirrel/Role.pm new file mode 100644 index 0000000..dfcb2e5 --- /dev/null +++ b/lib/Squirrel/Role.pm @@ -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; +