line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
{package MooseX::CompileTime::Traits; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
2
|
|
|
2
|
|
3238118
|
$MooseX::CompileTime::Traits::VERSION = '1.102570'; |
4
|
|
|
|
|
|
|
}} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#ABSTRACT: Allow compile time traits for classes/roles |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
883
|
use MooseX::Declare; |
|
2
|
|
|
|
|
3033176
|
|
|
2
|
|
|
|
|
94
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
203124
|
role MooseX::CompileTime::Traits { |
|
2
|
|
|
2
|
|
6
|
|
|
2
|
|
|
2
|
|
102
|
|
|
2
|
|
|
2
|
|
30359
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
23
|
|
|
2
|
|
|
|
|
9607
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
24
|
|
|
2
|
|
|
|
|
191
|
|
12
|
2
|
|
|
2
|
|
84
|
use Moose::Util; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
17
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
450736
|
method import (ClassName $class: ArrayRef :$traits?) { |
16
|
|
|
|
|
|
|
if(defined($traits)) |
17
|
|
|
|
|
|
|
{ |
18
|
|
|
|
|
|
|
my $meta = $class->meta; |
19
|
|
|
|
|
|
|
if($meta->isa('Moose::Meta::Class') && $meta->is_immutable) |
20
|
|
|
|
|
|
|
{ |
21
|
|
|
|
|
|
|
$meta->make_mutable(); |
22
|
|
|
|
|
|
|
Moose::Util::apply_all_roles($meta, @$traits); |
23
|
|
|
|
|
|
|
$meta->make_immutable(); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
else |
26
|
|
|
|
|
|
|
{ |
27
|
|
|
|
|
|
|
Moose::Util::apply_all_roles($meta, @$traits); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
2
|
|
|
2
|
|
3507
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
MooseX::CompileTime::Traits - Allow compile time traits for classes/roles |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 VERSION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
version 1.102570 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
role Bar(Int :$bar) { method bar { $bar + 2 } } |
50
|
|
|
|
|
|
|
role Baz(Int :$baz) { method baz { $baz + 4 } } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
class Foo with MooseX::CompileTime::Traits { } |
53
|
|
|
|
|
|
|
class Flarg with MooseX::CompileTime::Traits { } |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
... |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
use Foo traits => [ Bar => { bar => 2 } ]; |
58
|
|
|
|
|
|
|
use Flarg traits => [ Bar => { bar => 1 }, Baz => { baz => 1} ]; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Foo->new()->bar(); # 4 |
61
|
|
|
|
|
|
|
my $flarg = Flarg->new(); |
62
|
|
|
|
|
|
|
$flarg->bar(); # 3 |
63
|
|
|
|
|
|
|
$flarg->baz(); # 5 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
MooseX::CompileTime::Traits allows role application at compile time via use |
68
|
|
|
|
|
|
|
statements. What this class does is provide an import method that will apply |
69
|
|
|
|
|
|
|
each of the roles (along with any arguments for parameterized roles). |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Roles and their arguments should be provided as an ArrayRef of tuples. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Simply 'with' the role to gain the functionality |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 PUBLIC_METHODS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 import |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
(ClassName $class: ArrayRef :$traits?) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
import is provided such that when your class or role is use'd it can take |
82
|
|
|
|
|
|
|
additional arguments that will be validatated and interpreted as roles or |
83
|
|
|
|
|
|
|
traits that need to be applied. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTHOR |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Nicholas Perez <nperez@cpan.org> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This software is copyright (c) 2010 by Infinity Interactive. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
94
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |
100
|
|
|
|
|
|
|
|