Tweaks
[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 {
382b7340 8 backend => 'Moose',
692e1bcd 9 import => \&Moose::import,
10 unimport => \&Moose::unimport,
382b7340 11 };
692e1bcd 12 } else {
13 require Mouse;
14 return {
382b7340 15 backend => 'Mouse',
692e1bcd 16 import => \&Mouse::import,
17 unimport => \&Mouse::unimport,
382b7340 18 };
692e1bcd 19 }
20}
21
22my %pkgs;
23
24sub _handlers {
25 my $class = shift;
26
27 my $caller = caller(1);
28
b4bd06fa 29 $pkgs{$caller} ||= $class->_choose_backend;
692e1bcd 30}
31
32sub import {
2df74b3a 33 require Carp;
34 Carp::carp("Squirrel is deprecated. Please use Any::Moose instead. It fixes a number of design problems that Squirrel has.");
382b7340 35
36 my $handlers = shift->_handlers;
37 unshift @_, $handlers->{backend};
38 goto &{$handlers->{import}};
692e1bcd 39}
40
41sub unimport {
382b7340 42 my $handlers = shift->_handlers;
43 unshift @_, $handlers->{backend};
44 goto &{$handlers->{unimport}};
692e1bcd 45}
46
a5053119 471;
692e1bcd 48
49__END__
50
51=pod
52
53=head1 NAME
54
31c5194b 55Squirrel - Use Mouse, unless Moose is already loaded. (DEPRECATED)
692e1bcd 56
57=head1 SYNOPSIS
58
31c5194b 59 use Squirrel;
692e1bcd 60
61 has goggles => (
62 is => "rw",
63 );
64
a7387a2a 65=head1 DEPRECATION
66
1820fffe 67C<Squirrel> is deprecated. C<Any::Moose> provides the same functionality,
a7387a2a 68but better. :)
69
692e1bcd 70=head1 DESCRIPTION
71
1820fffe 72L<Moose> and L<Squirrel> are THE BEST FRIENDS, but if L<Moose> isn't there
103ad0e3 73L<Squirrel> will hang out with L<Mouse> as well.
692e1bcd 74
75When your own code doesn't actually care whether or not you use L<Moose> or
76L<Mouse> you can use either, and let your users decide for you.
77
78This lets you run with minimal dependencies and have a faster startup, but if
d25ab495 79L<Moose> is already in use you get all the benefits of using that
80(transformability, introspection, more opportunities for code reuse, etc).
692e1bcd 81
1820fffe 82=head1 SEE ALSO
83
84L<Any::Moose>
85
692e1bcd 86=cut
87
88