Ensure that "has '+nonexistent'" fails
[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
eb061d5b 30 $pkgs{$caller} = $class->_choose_backend
31 unless $pkgs{$caller};
692e1bcd 32}
33
34sub import {
35 goto $_[0]->_handlers->{import};
36}
37
38sub unimport {
39 goto $_[0]->_handlers->{unimport};
40}
41
42__PACKAGE__
43
44__END__
45
46=pod
47
48=head1 NAME
49
50Squirrel - 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
62L<Moose> and L<Squirrel> are TEH BEST FRENDS, but if L<Moose> isn't there
103ad0e3 63L<Squirrel> will hang out with L<Mouse> as well.
692e1bcd 64
65When your own code doesn't actually care whether or not you use L<Moose> or
66L<Mouse> you can use either, and let your users decide for you.
67
68This lets you run with minimal dependencies and have a faster startup, but if
d25ab495 69L<Moose> is already in use you get all the benefits of using that
70(transformability, introspection, more opportunities for code reuse, etc).
692e1bcd 71
72=cut
73
74