MethodAttributes/Role/Meta/Role.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod n/a totaltotal 93.7% 60 / 64 CC 2 SCAR 2.0
CC
2
Cov
94%
__ANON__
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.2
« MethodAttributes/Role/Meta/Map.pm ↑ Summary MethodAttributes/Role/AttrContainer.pm »
1 package MooseX::MethodAttributes::Role::Meta::Role;
2 # ABSTRACT: metarole role for storing code attributes
3  
4 21 our $VERSION = '0.32';
5  
6 21 ▶use Moose ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use Moose::Util::MetaRole;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use Moose::Util qw/find_meta does_role ensure_all_roles/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 21 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 21 ▶use MooseX::MethodAttributes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 21 ▶use MooseX::MethodAttributes::Role ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 21 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 #pod =head1 SYNOPSIS
18 #pod
19 #pod package MyRole;
20 #pod use MooseX::MethodAttributes::Role;
21 #pod
22 #pod sub foo : Bar Baz('corge') { ... }
23 #pod
24 #pod package MyClass
25 #pod use Moose;
26 #pod
27 #pod with 'MyRole';
28 #pod
29 #pod my $attrs = MyClass->meta->get_method('foo')->attributes; # ["Bar", "Baz('corge')"]
30 #pod
31 #pod =head1 DESCRIPTION
32 #pod
33 #pod This module is a metaclass role which is applied by L<MooseX::MethodAttributes::Role>, allowing
34 #pod you to add code attributes to methods in Moose roles.
35 #pod
36 #pod These attributes can then be found by introspecting the role metaclass, and are automatically copied
37 #pod into any classes or roles that the role is composed onto.
38 #pod
39 #pod =head1 CAVEATS
40 #pod
41 #pod =over
42 #pod
43 #pod =item *
44 #pod
45 #pod Currently roles with attributes cannot have methods excluded
46 #pod or aliased, and will in turn confer this property onto any roles they
47 #pod are composed onto.
48 #pod
49 #pod =back
50 #pod
51 #pod =cut
52  
53 21 with qw/
54 MooseX::MethodAttributes::Role::Meta::Map
55 MooseX::MethodAttributes::Role::Meta::Role::Application
56 /;
57  
58 $Moose::VERSION >= 0.9301
59 10 ▶ ? around composition_class_roles => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
60 10 my ($orig, $self) = @_;
61 10 return $self->$orig,
62 'MooseX::MethodAttributes::Role::Meta::Role::Application::Summation';
63 }
64 : has '+composition_class_roles' => (
65 0 ▶ default => sub { [ 'MooseX::MethodAttributes::Role::Meta::Role::Application::Summation' ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 21 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$Moose::VERSION >= 0.9301 ? : 21 0 21
67  
68 #pod =method initialize
69 #pod
70 #pod Ensures that the package containing the role methods does the
71 #pod L<MooseX::MethodAttributes::Role::AttrContainer> role during initialisation,
72 #pod which in turn is responsible for capturing the method attributes on the class
73 #pod and registering them with the metaclass.
74 #pod
75 #pod =cut
76  
77 19 ▶after 'initialize' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
78 19 my ($self, $class, %args) = @_;
79 19 ensure_all_roles($class, 'MooseX::MethodAttributes::Role::AttrContainer');
80 21 };
81  
82 #pod =method method_metaclass
83 #pod
84 #pod Wraps the normal method and ensures that the method metaclass performs the
85 #pod L<MooseX::MethodAttributes::Role::Meta::Method> role, which allows you to
86 #pod introspect the attributes from the method objects returned by the MOP when
87 #pod querying the metaclass.
88 #pod
89 #pod =cut
90  
91 # FIXME - Skip this logic if the method metaclass already does the right role?
92 48 ▶around method_metaclass => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
93 48 my $orig = shift;
94 48 my $self = shift;
95 48 ▶ return $self->$orig(@_) if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 48 48
96 48 Moose::Meta::Class->create_anon_class(
97 superclasses => [ $self->$orig ],
98 roles => [qw/
99 MooseX::MethodAttributes::Role::Meta::Method
100 /],
101 cache => 1,
102 )->name();
103 21 };
104  
105  
106 14 ▶sub _copy_attributes {
Subroutine _copy_attributes: called CC=1 SCAR=0.0
107 14 my ($self, $thing) = @_;
108  
109 14 push @{ $thing->_method_attribute_list }, @{ $self->_method_attribute_list };
110 14 @{ $thing->_method_attribute_map }{ (keys(%{ $self->_method_attribute_map }), keys(%{ $thing->_method_attribute_map })) }
111 14 = (values(%{ $self->_method_attribute_map }), values(%{ $thing->_method_attribute_map }));
112 };
113  
114 # This allows you to say use Moose::Role -traits => 'MethodAttributes'
115 # This is replaced by MooseX::MethodAttributes::Role, and this trait registration
116 # is now only present for backwards compatibility reasons.
117 package # Hide from PAUSE
118 Moose::Meta::Role::Custom::Trait::MethodAttributes;
119  
120 7 ▶sub register_implementation { 'MooseX::MethodAttributes::Role::Meta::Role' }
Subroutine register_implementation: called CC=1 SCAR=0.0
121  
122 21 1;
123  
124 __END__
« MethodAttributes/Role/Meta/Map.pm ↑ Summary MethodAttributes/Role/AttrContainer.pm »