Commit | Line | Data |
9baf5d6b |
1 | #!/usr/bin/env perl |
ce2ee568 |
2 | package Squirrel::Role; |
ce2ee568 |
3 | use strict; |
4 | use warnings; |
5 | |
6 | sub _choose_backend { |
7 | if ( $INC{"Moose/Role.pm"} ) { |
8 | return { |
9 | import => \&Moose::Role::import, |
ddd4992c |
10 | unimport => defined &Moose::Role::unimport ? \&Moose::Role::unimport : sub {}, |
ce2ee568 |
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 | |