More 0.20 changes
[gitmo/Mouse.git] / lib / Squirrel.pm
CommitLineData
692e1bcd 1package Squirrel;
692e1bcd 2use strict;
3use warnings;
4
5sub _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
20my %pkgs;
21
22sub _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
31sub import {
32 goto $_[0]->_handlers->{import};
33}
34
35sub unimport {
36 goto $_[0]->_handlers->{unimport};
37}
38
a5053119 391;
692e1bcd 40
41__END__
42
43=pod
44
45=head1 NAME
46
47Squirrel - 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
59L<Squirrel> is being deprecated. L<Any::Moose> provides the same functionality,
60but better. :)
61
692e1bcd 62=head1 DESCRIPTION
63
64L<Moose> and L<Squirrel> are TEH BEST FRENDS, but if L<Moose> isn't there
103ad0e3 65L<Squirrel> will hang out with L<Mouse> as well.
692e1bcd 66
67When your own code doesn't actually care whether or not you use L<Moose> or
68L<Mouse> you can use either, and let your users decide for you.
69
70This lets you run with minimal dependencies and have a faster startup, but if
d25ab495 71L<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