Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Moose / Autobox.pm
CommitLineData
3fea05b9 1
2package Moose::Autobox;
3use 5.006;
4use strict;
5use warnings;
6
7use Carp qw(confess);
8use Scalar::Util ();
9use Moose::Util ();
10
11our $VERSION = '0.10';
12
13use base 'autobox';
14
15use Moose::Autobox::Undef;
16
17sub import {
18 (shift)->SUPER::import(
19 DEFAULT => 'Moose::Autobox::',
20 UNDEF => 'Moose::Autobox::Undef',
21 );
22}
23
24sub mixin_additional_role {
25 my ($class, $type, $role) = @_;
26 ($type =~ /SCALAR|ARRAY|HASH|CODE/)
27 || confess "Can only add additional roles to SCALAR, ARRAY, HASH or CODE";
28 Moose::Util::apply_all_roles(('Moose::Autobox::' . $type)->meta, ($role));
29}
30
31{
32
33 package Moose::Autobox::SCALAR;
34
35 use Moose::Autobox::Scalar;
36
37 use metaclass 'Moose::Meta::Class';
38
39 Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Scalar'));
40
41 *does = \&Moose::Object::does;
42
43 package Moose::Autobox::ARRAY;
44
45 use Moose::Autobox::Array;
46
47 use metaclass 'Moose::Meta::Class';
48
49 Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Array'));
50
51 *does = \&Moose::Object::does;
52
53 package Moose::Autobox::HASH;
54
55 use Moose::Autobox::Hash;
56
57 use metaclass 'Moose::Meta::Class';
58
59 Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Hash'));
60
61 *does = \&Moose::Object::does;
62
63 package Moose::Autobox::CODE;
64
65 use Moose::Autobox::Code;
66
67 use metaclass 'Moose::Meta::Class';
68
69 Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Code'));
70
71 *does = \&Moose::Object::does;
72
73}
74
751;
76
77__END__
78
79=pod
80
81=head1 NAME
82
83Moose::Autobox - Autoboxed wrappers for Native Perl datatypes
84
85=head1 SYNOPOSIS
86
87 use Moose::Autobox;
88
89 print 'Print squares from 1 to 10 : ';
90 print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
91
92=head1 DESCRIPTION
93
94Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH
95& CODE for use with L<autobox>. It does this using a hierarchy of
96roles in a manner similar to what Perl 6 I<might> do. This module,
97like L<Class::MOP> and L<Moose>, was inspired by my work on the
98Perl 6 Object Space, and the 'core types' implemented there.
99
100=head2 A quick word about autobox
101
102The L<autobox> module provides the ability for calling 'methods'
103on normal Perl values like Scalars, Arrays, Hashes and Code
104references. This gives the illusion that Perl's types are first-class
105objects. However, this is only an illusion, albeit a very nice one.
106I created this module because L<autobox> itself does not actually
107provide an implementation for the Perl types but instead only provides
108the 'hooks' for others to add implementation too.
109
110=head2 Is this for real? or just play?
111
112Several people are using this module in serious applications and
113it seems to be quite stable. The underlying technologies of L<autobox>
114and L<Moose::Role> are also considered stable. There is some performance
115hit, but as I am fond of saying, nothing in life is free. If you have
116any questions regarding this module, either email me, or stop by #moose
117on irc.perl.org and ask around.
118
119=head2 Adding additional methods
120
121B<Moose::Autobox> asks L<autobox> to use the B<Moose::Autobox::*> namespace
122prefix so as to avoid stepping on the toes of other L<autobox> modules. This
123means that if you want to add methods to a particular perl type
124(i.e. - monkeypatch), then you must do this:
125
126 sub Moose::Autobox::SCALAR::bar { 42 }
127
128instead of this:
129
130 sub SCALAR::bar { 42 }
131
132as you would with vanilla autobox.
133
134=head1 METHODS
135
136=over 4
137
138=item B<mixin_additional_role ($type, $role)>
139
140This will mixin an additonal C<$role> into a certain C<$type>. The
141types can be SCALAR, ARRAY, HASH or CODE.
142
143This can be used to add additional methods to the types, see the
144F<examples/units/> directory for some examples.
145
146=back
147
148=head1 TODO
149
150=over 4
151
152=item More docs
153
154=item More tests
155
156=back
157
158=head1 BUGS
159
160All complex software has bugs lurking in it, and this module is no
161exception. If you find a bug please either email me, or add the bug
162to cpan-RT.
163
164=head1 AUTHOR
165
166Stevan Little E<lt>stevan@iinteractive.comE<gt>
167
168B<with contributions from:>
169
170Anders (Debolaz) Nor Berle
171
172Matt (mst) Trout
173
174renormalist
175
176=head1 COPYRIGHT AND LICENSE
177
178Copyright 2006-2008 by Infinity Interactive, Inc.
179
180L<http://www.iinteractive.com>
181
182This library is free software; you can redistribute it and/or modify
183it under the same terms as Perl itself.
184
185=cut