line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MouseX::Traits; |
2
|
3
|
|
|
3
|
|
65410
|
use Mouse::Role; |
|
3
|
|
|
|
|
48166
|
|
|
3
|
|
|
|
|
28
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.1102'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has '_trait_namespace' => ( |
7
|
|
|
|
|
|
|
init_arg => undef, |
8
|
|
|
|
|
|
|
isa => 'Str', |
9
|
|
|
|
|
|
|
is => 'bare', |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $transform_trait = sub { |
13
|
|
|
|
|
|
|
my ($class, $name) = @_; |
14
|
|
|
|
|
|
|
return $1 if $name =~ /^[+](.+)$/; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $namespace = $class->meta->find_attribute_by_name('_trait_namespace'); |
17
|
|
|
|
|
|
|
my $base; |
18
|
|
|
|
|
|
|
if($namespace->has_default){ |
19
|
|
|
|
|
|
|
$base = $namespace->default; |
20
|
|
|
|
|
|
|
if(ref $base eq 'CODE'){ |
21
|
|
|
|
|
|
|
$base = $base->(); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return $name unless defined $base; |
26
|
|
|
|
|
|
|
return join '::', $base, $name; |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $anon_serial = 0; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub with_traits { |
33
|
9
|
|
|
9
|
1
|
27776
|
my ($class, @traits) = @_; |
34
|
|
|
|
|
|
|
|
35
|
9
|
50
|
|
|
|
65
|
$class->does(__PACKAGE__) |
36
|
|
|
|
|
|
|
or Carp::confess("We can't interact with traits for a class ($class) " |
37
|
|
|
|
|
|
|
. "that does not do MouseX::Traits"); |
38
|
|
|
|
|
|
|
|
39
|
9
|
|
|
|
|
510
|
my $meta = $class->meta; |
40
|
9
|
100
|
|
|
|
271
|
if (@traits) { |
41
|
|
|
|
|
|
|
# resolve traits |
42
|
8
|
|
|
|
|
23
|
@traits = map { |
43
|
7
|
|
|
|
|
20
|
my $orig = $_; |
44
|
8
|
50
|
|
|
|
25
|
if(!ref $orig){ |
45
|
8
|
|
|
|
|
24
|
my $transformed = $transform_trait->($class, $orig); |
46
|
8
|
|
|
|
|
41
|
Mouse::Util::load_class($transformed); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
0
|
|
|
|
|
0
|
$orig; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} @traits; |
52
|
|
|
|
|
|
|
|
53
|
7
|
|
|
|
|
10693
|
$meta = $meta->create( |
54
|
|
|
|
|
|
|
'MouseX::Traits::__ANON__::' . ++$anon_serial, |
55
|
|
|
|
|
|
|
superclasses => [ $class ], |
56
|
|
|
|
|
|
|
roles => \@traits, |
57
|
|
|
|
|
|
|
cache => 1, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
9
|
|
|
|
|
18426
|
return $meta->name; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new_with_traits { |
65
|
3
|
|
|
3
|
1
|
15654
|
my $class = shift; |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
25
|
my $args = $class->BUILDARGS(@_); |
68
|
3
|
|
50
|
|
|
19
|
my $traits = delete $args->{traits} || []; |
69
|
|
|
|
|
|
|
|
70
|
3
|
100
|
|
|
|
22
|
my $new_class = $class->with_traits(ref $traits ? @$traits : $traits ); |
71
|
3
|
|
|
|
|
24
|
return $new_class->meta->new_object($args); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
3
|
|
|
3
|
|
2507
|
no Mouse::Role; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
18
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |