We don't need to do both eval and Module::Name -> Module/Name.pm munging
[gitmo/Mouse.git] / lib / Squirrel / Role.pm
1 #!/usr/bin/env perl
2 package Squirrel::Role;
3 use strict;
4 use warnings;
5
6 sub _choose_backend {
7     if ( $INC{"Moose/Role.pm"} ) {
8         return {
9             import   => \&Moose::Role::import,
10             unimport => defined &Moose::Role::unimport ? \&Moose::Role::unimport : sub {},
11         }
12     } else {
13         require Mouse::Role;
14         return {
15             import   => \&Mouse::Role::import,
16             unimport => \&Mouse::Role::unimport,
17         }
18     }
19 }
20
21 my %pkgs;
22
23 sub _handlers {
24     my $class = shift;
25
26     my $caller = caller(1);
27
28     $pkgs{$caller} = $class->_choose_backend
29         unless $pkgs{$caller};
30 }
31
32 sub import {
33     goto $_[0]->_handlers->{import};
34 }
35
36 sub unimport {
37     goto $_[0]->_handlers->{unimport};
38 }
39
40 1;
41