Inline $from
[gitmo/Mouse.git] / lib / Squirrel.pm
CommitLineData
9baf5d6b 1#!/usr/bin/env perl
692e1bcd 2package Squirrel;
692e1bcd 3use strict;
4use warnings;
5
6sub _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
21my %pkgs;
22
23sub _handlers {
24 my $class = shift;
25
26 my $caller = caller(1);
27
eb061d5b 28 $pkgs{$caller} = $class->_choose_backend
29 unless $pkgs{$caller};
692e1bcd 30}
31
32sub import {
33 goto $_[0]->_handlers->{import};
34}
35
36sub unimport {
37 goto $_[0]->_handlers->{unimport};
38}
39
a5053119 401;
692e1bcd 41
42__END__
43
44=pod
45
46=head1 NAME
47
48Squirrel - 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
60L<Moose> and L<Squirrel> are TEH BEST FRENDS, but if L<Moose> isn't there
103ad0e3 61L<Squirrel> will hang out with L<Mouse> as well.
692e1bcd 62
63When your own code doesn't actually care whether or not you use L<Moose> or
64L<Mouse> you can use either, and let your users decide for you.
65
66This lets you run with minimal dependencies and have a faster startup, but if
d25ab495 67L<Moose> is already in use you get all the benefits of using that
68(transformability, introspection, more opportunities for code reuse, etc).
692e1bcd 69
70=cut
71
72