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