Add type constraint
[gitmo/Mouse.git] / lib / Squirrel.pm
1 package Squirrel;
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
27     $pkgs{$caller} = $class->_choose_backend
28         unless $pkgs{$caller};
29 }
30
31 sub import {
32     goto $_[0]->_handlers->{import};
33 }
34
35 sub unimport {
36     goto $_[0]->_handlers->{unimport};
37 }
38
39 1;
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
57 =head1 DESCRIPTION
58
59 L<Moose> and L<Squirrel> are TEH BEST FRENDS, but if L<Moose> isn't there
60 L<Squirrel> will hang out with L<Mouse> as well.
61
62 When your own code doesn't actually care whether or not you use L<Moose> or
63 L<Mouse> you can use either, and let your users decide for you.
64
65 This lets you run with minimal dependencies and have a faster startup, but if
66 L<Moose> is already in use you get all the benefits of using that
67 (transformability, introspection, more opportunities for code reuse, etc).
68
69 =cut
70
71