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