"type" sugar for when you're not subtyping anything
[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
57=head1 DESCRIPTION
58
59L<Moose> and L<Squirrel> are TEH BEST FRENDS, but if L<Moose> isn't there
103ad0e3 60L<Squirrel> will hang out with L<Mouse> as well.
692e1bcd 61
62When your own code doesn't actually care whether or not you use L<Moose> or
63L<Mouse> you can use either, and let your users decide for you.
64
65This lets you run with minimal dependencies and have a faster startup, but if
d25ab495 66L<Moose> is already in use you get all the benefits of using that
67(transformability, introspection, more opportunities for code reuse, etc).
692e1bcd 68
69=cut
70
71