use teh Squirrel
[gitmo/Mouse.git] / lib / Squirrel.pm
CommitLineData
692e1bcd 1#!/usr/bin/perl
2
3package Squirrel;
4
5use strict;
6use warnings;
7
8sub _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
23my %pkgs;
24
25sub _handlers {
26 my $class = shift;
27
28 my $caller = caller(1);
29
30 $pkgs{$caller} ||= $class->_choose_backend;
31}
32
33sub import {
34 goto $_[0]->_handlers->{import};
35}
36
37sub unimport {
38 goto $_[0]->_handlers->{unimport};
39}
40
41__PACKAGE__
42
43__END__
44
45=pod
46
47=head1 NAME
48
49Squirrel - Use L<Mouse>, unless L<Moose> is already loaded.
50
51=head1 SYNOPSIS
52
53 use Squirrel;
54
55 has goggles => (
56 is => "rw",
57 );
58
59=head1 DESCRIPTION
60
61L<Moose> and L<Squirrel> are TEH BEST FRENDS, but if L<Moose> isn't there
62L<Squirrel> will hang out with L<Mouse> as too.
63
64When your own code doesn't actually care whether or not you use L<Moose> or
65L<Mouse> you can use either, and let your users decide for you.
66
67This lets you run with minimal dependencies and have a faster startup, but if
68L<Moose> is already in use you get all the benefits of using that.
69
70=cut
71
72