line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package metaclass; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2205'; |
3
|
|
|
|
|
|
|
|
4
|
429
|
|
|
429
|
|
819749
|
use strict; |
|
429
|
|
|
|
|
1024
|
|
|
429
|
|
|
|
|
12992
|
|
5
|
429
|
|
|
429
|
|
2257
|
use warnings; |
|
429
|
|
|
|
|
966
|
|
|
429
|
|
|
|
|
12546
|
|
6
|
|
|
|
|
|
|
|
7
|
429
|
|
|
429
|
|
12704
|
use Module::Runtime 'use_package_optimistically', 'use_module'; |
|
429
|
|
|
|
|
35973
|
|
|
429
|
|
|
|
|
3452
|
|
8
|
429
|
|
|
429
|
|
37258
|
use Class::MOP; |
|
429
|
|
|
|
|
1046
|
|
|
429
|
|
|
|
|
128465
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
7821
|
|
|
7821
|
|
45685
|
my ( $class, @args ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
7821
|
100
|
|
|
|
28744
|
unshift @args, "metaclass" if @args % 2 == 1; |
14
|
7821
|
|
|
|
|
16152
|
my %options = @args; |
15
|
|
|
|
|
|
|
|
16
|
7821
|
100
|
|
|
|
21451
|
my $meta_name = exists $options{meta_name} ? $options{meta_name} : 'meta'; |
17
|
7821
|
|
|
|
|
13449
|
my $metaclass = delete $options{metaclass}; |
18
|
|
|
|
|
|
|
|
19
|
7821
|
100
|
|
|
|
16512
|
unless ( defined $metaclass ) { |
20
|
7413
|
|
|
|
|
11766
|
$metaclass = "Class::MOP::Class"; |
21
|
|
|
|
|
|
|
} else { |
22
|
408
|
|
|
|
|
1908
|
use_package_optimistically($metaclass); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
7821
|
100
|
|
|
|
83287
|
($metaclass->isa('Class::MOP::Class')) |
26
|
|
|
|
|
|
|
|| die use_module('Moose::Exception::MetaclassMustBeDerivedFromClassMOPClass')->new( class_name => $metaclass ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# make sure the custom metaclasses get loaded |
29
|
7819
|
|
|
|
|
24185
|
foreach my $key (grep { /_(?:meta)?class$/ } keys %options) { |
|
43
|
|
|
|
|
314
|
|
30
|
38
|
50
|
|
|
|
4401
|
unless ( ref( my $class = $options{$key} ) ) { |
31
|
38
|
|
|
|
|
122
|
use_package_optimistically($class) |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
7819
|
|
|
|
|
22802
|
my $package = caller(); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# create a meta object so we can install &meta |
38
|
7819
|
|
|
|
|
28585
|
my $meta = $metaclass->initialize($package => %options); |
39
|
7816
|
100
|
|
|
|
42237
|
$meta->_add_meta_method($meta_name) |
40
|
|
|
|
|
|
|
if defined $meta_name; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# ABSTRACT: a pragma for installing and using Class::MOP metaclasses |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=pod |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=encoding UTF-8 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
metaclass - a pragma for installing and using Class::MOP metaclasses |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 VERSION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
version 2.2205 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
package MyClass; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# use Class::MOP::Class |
66
|
|
|
|
|
|
|
use metaclass; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# ... or use a custom metaclass |
69
|
|
|
|
|
|
|
use metaclass 'MyMetaClass'; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# ... or use a custom metaclass |
72
|
|
|
|
|
|
|
# and custom attribute and method |
73
|
|
|
|
|
|
|
# metaclasses |
74
|
|
|
|
|
|
|
use metaclass 'MyMetaClass' => ( |
75
|
|
|
|
|
|
|
'attribute_metaclass' => 'MyAttributeMetaClass', |
76
|
|
|
|
|
|
|
'method_metaclass' => 'MyMethodMetaClass', |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# ... or just specify custom attribute |
80
|
|
|
|
|
|
|
# and method classes, and Class::MOP::Class |
81
|
|
|
|
|
|
|
# is the assumed metaclass |
82
|
|
|
|
|
|
|
use metaclass ( |
83
|
|
|
|
|
|
|
'attribute_metaclass' => 'MyAttributeMetaClass', |
84
|
|
|
|
|
|
|
'method_metaclass' => 'MyMethodMetaClass', |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# if we'd rather not install a 'meta' method, we can do this |
88
|
|
|
|
|
|
|
use metaclass meta_name => undef; |
89
|
|
|
|
|
|
|
# or if we'd like it to have a different name, |
90
|
|
|
|
|
|
|
use metaclass meta_name => 'my_meta'; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 DESCRIPTION |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This is a pragma to make it easier to use a specific metaclass |
95
|
|
|
|
|
|
|
and a set of custom attribute and method metaclasses. It also |
96
|
|
|
|
|
|
|
installs a C<meta> method to your class as well, unless C<undef> |
97
|
|
|
|
|
|
|
is passed to the C<meta_name> option. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Note that if you are using Moose, you most likely do B<not> want |
100
|
|
|
|
|
|
|
to be using this - look into L<Moose::Util::MetaRole> instead. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHORS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over 4 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Jesse Luehrs <doy@cpan.org> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Shawn M Moore <sartak@cpan.org> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@cpan.org> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Matt S Trout <mstrout@cpan.org> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=back |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
153
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |