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