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