We don't need to do both eval and Module::Name -> Module/Name.pm munging
[gitmo/Mouse.git] / lib / Squirrel / Role.pm
CommitLineData
9baf5d6b 1#!/usr/bin/env perl
ce2ee568 2package Squirrel::Role;
ce2ee568 3use strict;
4use warnings;
5
6sub _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
21my %pkgs;
22
23sub _handlers {
24 my $class = shift;
25
26 my $caller = caller(1);
27
28 $pkgs{$caller} = $class->_choose_backend
29 unless $pkgs{$caller};
30}
31
32sub import {
33 goto $_[0]->_handlers->{import};
34}
35
36sub unimport {
37 goto $_[0]->_handlers->{unimport};
38}
39
401;
41