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