Commit | Line | Data |
692e1bcd |
1 | #!/usr/bin/perl |
2 | |
3 | package Squirrel; |
4 | |
5 | use strict; |
6 | use warnings; |
7 | |
8 | sub _choose_backend { |
9 | if ( $INC{"Moose.pm"} ) { |
10 | return { |
11 | import => \&Moose::import, |
12 | unimport => \&Moose::unimport, |
13 | } |
14 | } else { |
15 | require Mouse; |
16 | return { |
17 | import => \&Mouse::import, |
18 | unimport => \&Mouse::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 | } |
32 | |
33 | sub import { |
34 | goto $_[0]->_handlers->{import}; |
35 | } |
36 | |
37 | sub unimport { |
38 | goto $_[0]->_handlers->{unimport}; |
39 | } |
40 | |
41 | __PACKAGE__ |
42 | |
43 | __END__ |
44 | |
45 | =pod |
46 | |
47 | =head1 NAME |
48 | |
49 | Squirrel - Use L<Mouse>, unless L<Moose> is already loaded. |
50 | |
51 | =head1 SYNOPSIS |
52 | |
53 | use Squirrel; |
54 | |
55 | has goggles => ( |
56 | is => "rw", |
57 | ); |
58 | |
59 | =head1 DESCRIPTION |
60 | |
61 | L<Moose> and L<Squirrel> are TEH BEST FRENDS, but if L<Moose> isn't there |
103ad0e3 |
62 | L<Squirrel> will hang out with L<Mouse> as well. |
692e1bcd |
63 | |
64 | When your own code doesn't actually care whether or not you use L<Moose> or |
65 | L<Mouse> you can use either, and let your users decide for you. |
66 | |
67 | This lets you run with minimal dependencies and have a faster startup, but if |
d25ab495 |
68 | L<Moose> is already in use you get all the benefits of using that |
69 | (transformability, introspection, more opportunities for code reuse, etc). |
692e1bcd |
70 | |
71 | =cut |
72 | |
73 | |