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