line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Autobox; # git description: 0_09-64-ge6e9586 |
2
|
|
|
|
|
|
|
# ABSTRACT: Autoboxed wrappers for Native Perl datatypes |
3
|
14
|
|
|
14
|
|
3237230
|
use 5.006; |
|
14
|
|
|
|
|
46
|
|
4
|
14
|
|
|
14
|
|
64
|
use strict; |
|
14
|
|
|
|
|
15
|
|
|
14
|
|
|
|
|
300
|
|
5
|
14
|
|
|
14
|
|
59
|
use warnings; |
|
14
|
|
|
|
|
20
|
|
|
14
|
|
|
|
|
374
|
|
6
|
|
|
|
|
|
|
|
7
|
14
|
|
|
14
|
|
63
|
use Carp (); |
|
14
|
|
|
|
|
59
|
|
|
14
|
|
|
|
|
222
|
|
8
|
14
|
|
|
14
|
|
55
|
use Scalar::Util (); |
|
14
|
|
|
|
|
15
|
|
|
14
|
|
|
|
|
198
|
|
9
|
14
|
|
|
14
|
|
6337
|
use Moose::Util (); |
|
14
|
|
|
|
|
1324360
|
|
|
14
|
|
|
|
|
813
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
12
|
|
|
|
|
|
|
|
13
|
14
|
|
|
14
|
|
103
|
use parent 'autobox'; |
|
14
|
|
|
|
|
19
|
|
|
14
|
|
|
|
|
87
|
|
14
|
|
|
|
|
|
|
|
15
|
14
|
|
|
14
|
|
103075
|
use Moose::Autobox::Undef; |
|
14
|
|
|
|
|
45
|
|
|
14
|
|
|
|
|
2623
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub import { |
18
|
55
|
|
|
55
|
|
1477
|
(shift)->SUPER::import( |
19
|
|
|
|
|
|
|
DEFAULT => 'Moose::Autobox::', |
20
|
|
|
|
|
|
|
UNDEF => 'Moose::Autobox::Undef', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub mixin_additional_role { |
25
|
1
|
|
|
1
|
1
|
104
|
my ($class, $type, $role) = @_; |
26
|
1
|
50
|
|
|
|
10
|
($type =~ /SCALAR|ARRAY|HASH|CODE/) |
27
|
|
|
|
|
|
|
|| Carp::confess "Can only add additional roles to SCALAR, ARRAY, HASH or CODE"; |
28
|
1
|
|
|
|
|
11
|
Moose::Util::apply_all_roles(('Moose::Autobox::' . $type)->meta, ($role)); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
package |
33
|
|
|
|
|
|
|
Moose::Autobox::SCALAR; |
34
|
|
|
|
|
|
|
|
35
|
14
|
|
|
14
|
|
6184
|
use Moose::Autobox::Scalar; |
|
14
|
|
|
|
|
39
|
|
|
14
|
|
|
|
|
661
|
|
36
|
|
|
|
|
|
|
|
37
|
14
|
|
|
14
|
|
335
|
use metaclass 'Moose::Meta::Class'; |
|
14
|
|
|
|
|
18
|
|
|
14
|
|
|
|
|
106
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Scalar')); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
*does = \&Moose::Object::does; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
package |
44
|
|
|
|
|
|
|
Moose::Autobox::ARRAY; |
45
|
|
|
|
|
|
|
|
46
|
14
|
|
|
14
|
|
21670
|
use Moose::Autobox::Array; |
|
14
|
|
|
|
|
44
|
|
|
14
|
|
|
|
|
757
|
|
47
|
|
|
|
|
|
|
|
48
|
14
|
|
|
14
|
|
92
|
use metaclass 'Moose::Meta::Class'; |
|
14
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
112
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Array')); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
*does = \&Moose::Object::does; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
package |
55
|
|
|
|
|
|
|
Moose::Autobox::HASH; |
56
|
|
|
|
|
|
|
|
57
|
14
|
|
|
14
|
|
20488
|
use Moose::Autobox::Hash; |
|
14
|
|
|
|
|
41
|
|
|
14
|
|
|
|
|
652
|
|
58
|
|
|
|
|
|
|
|
59
|
14
|
|
|
14
|
|
87
|
use metaclass 'Moose::Meta::Class'; |
|
14
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
114
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Hash')); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
*does = \&Moose::Object::does; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
package |
66
|
|
|
|
|
|
|
Moose::Autobox::CODE; |
67
|
|
|
|
|
|
|
|
68
|
14
|
|
|
14
|
|
19711
|
use Moose::Autobox::Code; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
524
|
|
69
|
|
|
|
|
|
|
|
70
|
14
|
|
|
14
|
|
77
|
use metaclass 'Moose::Meta::Class'; |
|
14
|
|
|
|
|
18
|
|
|
14
|
|
|
|
|
92
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Code')); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
*does = \&Moose::Object::does; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=pod |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=encoding UTF-8 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=for :stopwords Autoboxed autobox |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Moose::Autobox - Autoboxed wrappers for Native Perl datatypes |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 VERSION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
version 0.16 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SYNOPSIS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use Moose::Autobox; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
print 'Print squares from 1 to 10 : '; |
100
|
|
|
|
|
|
|
print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', '); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 DESCRIPTION |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH |
105
|
|
|
|
|
|
|
& CODE for use with L<autobox>. It does this using a hierarchy of |
106
|
|
|
|
|
|
|
roles in a manner similar to what Perl 6 I<might> do. This module, |
107
|
|
|
|
|
|
|
like L<Class::MOP> and L<Moose>, was inspired by my work on the |
108
|
|
|
|
|
|
|
Perl 6 Object Space, and the 'core types' implemented there. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 A quick word about autobox |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
The L<autobox> module provides the ability for calling 'methods' |
113
|
|
|
|
|
|
|
on normal Perl values like Scalars, Arrays, Hashes and Code |
114
|
|
|
|
|
|
|
references. This gives the illusion that Perl's types are first-class |
115
|
|
|
|
|
|
|
objects. However, this is only an illusion, albeit a very nice one. |
116
|
|
|
|
|
|
|
I created this module because L<autobox> itself does not actually |
117
|
|
|
|
|
|
|
provide an implementation for the Perl types but instead only provides |
118
|
|
|
|
|
|
|
the 'hooks' for others to add implementation too. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 Is this for real? or just play? |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Several people are using this module in serious applications and |
123
|
|
|
|
|
|
|
it seems to be quite stable. The underlying technologies of L<autobox> |
124
|
|
|
|
|
|
|
and L<Moose::Role> are also considered stable. There is some performance |
125
|
|
|
|
|
|
|
hit, but as I am fond of saying, nothing in life is free. Note that this hit |
126
|
|
|
|
|
|
|
only applies to the I<use> of methods on native Perl values, not the mere act |
127
|
|
|
|
|
|
|
of loading this module in your namespace. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
If you have any questions regarding this module, either email me, or stop by |
130
|
|
|
|
|
|
|
#moose on irc.perl.org and ask around. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 Adding additional methods |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
B<Moose::Autobox> asks L<autobox> to use the B<Moose::Autobox::*> namespace |
135
|
|
|
|
|
|
|
prefix so as to avoid stepping on the toes of other L<autobox> modules. This |
136
|
|
|
|
|
|
|
means that if you want to add methods to a particular perl type |
137
|
|
|
|
|
|
|
(i.e. - monkeypatch), then you must do this: |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub Moose::Autobox::SCALAR::bar { 42 } |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
instead of this: |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub SCALAR::bar { 42 } |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
as you would with vanilla autobox. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 METHODS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item C<mixin_additional_role ($type, $role)> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This will mixin an additional C<$role> into a certain C<$type>. The |
154
|
|
|
|
|
|
|
types can be SCALAR, ARRAY, HASH or CODE. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This can be used to add additional methods to the types, see the |
157
|
|
|
|
|
|
|
F<examples/units/> directory for some examples. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=back |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=for :stopwords TODO |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 TODO |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=over 4 |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item More docs |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item More tests |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SUPPORT |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Moose-Autobox> |
176
|
|
|
|
|
|
|
(or L<bug-Moose-Autobox@rt.cpan.org|mailto:bug-Moose-Autobox@rt.cpan.org>). |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
179
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
182
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 AUTHOR |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Stevan Little <stevan.little@iinteractive.com> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=for stopwords Ricardo Signes Karen Etheridge Anders Nor Berle Matt S Trout Steffen Schwigon Michael Swearingen Florian Ragwitz Jonathan Rockway Shawn M Moore Todd Hepler David Steinbrunner Mike Whitaker Nigel Gregoire |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=over 4 |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Ricardo Signes <rjbs@cpan.org> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Anders Nor Berle <berle@cpan.org> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Matt S Trout <mst@shadowcat.co.uk> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Steffen Schwigon <ss5@renormalist.net> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Michael Swearingen <mswearingen@gmail.com> |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item * |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Jonathan Rockway <jon@jrock.us> |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item * |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Shawn M Moore <sartak@gmail.com> |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Todd Hepler <thepler@employees.org> |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item * |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
David Steinbrunner <dsteinbrunner@pobox.com> |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item * |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Mike Whitaker <mike@altrion.org> |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item * |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Nigel Gregoire <nigelgregoire@gmail.com> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=back |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
253
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=cut |