MethodAttributes/Role/Meta/Role/Application.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 95.5% 43 / 45 CC 3 SCAR 4.8
CC
3
Cov
95%
_apply_metaclasses
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« MethodAttributes/Role/Meta/Method/MaybeWrapped.pm ↑ Summary MethodAttributes/Role/AttrContainer/Inheritable.pm »
1 package MooseX::MethodAttributes::Role::Meta::Role::Application;
2 # ABSTRACT: generic role for applying a role with method attributes to something
3  
4 21 our $VERSION = '0.32';
5  
6 21 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use Moose::Util qw/find_meta/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use MooseX::MethodAttributes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 21 ▶use MooseX::MethodAttributes::Role ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 21 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 21 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 21 requires qw/
14 _copy_attributes
15 apply
16 /;
17  
18 #pod =method apply
19 #pod
20 #pod The apply method is wrapped to ensure that the correct metaclasses to hold and propagate
21 #pod method attribute data are present on the target for role application, delegates to
22 #pod the original method to actually apply the role, then ensures that any attributes from
23 #pod the role are copied to the target class.
24 #pod
25 #pod =cut
26  
27 15 ▶around 'apply' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
28 15 my ($orig, $self, $thing, %opts) = @_;
29 15 $thing = $self->_apply_metaclasses($thing);
30  
31 15 my $ret = $self->$orig($thing, %opts);
32  
33 12 $self->_copy_attributes($thing);
34  
35 12 return $ret;
36 21 };
37  
38 15 ▶sub _apply_metaclasses {
Subroutine _apply_metaclasses: called CC=3 SCAR=11.2
39 15 my ($self, $thing) = @_;
40 15 ▶ if ($thing->isa('Moose::Meta::Class')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($thing->isa('Moose::Meta::Class')) { } 13 2 15
elsif ($thing->isa('Moose::Meta::Role')) { } 2 0 2
41 13 $thing = MooseX::MethodAttributes->init_meta( for_class => $thing->name );
42 }
43 elsif ($thing->isa('Moose::Meta::Role')) {
44 2 $thing = MooseX::MethodAttributes::Role->init_meta( for_class => $thing->name );
45 }
46 else {
47 0 croak("Composing " . __PACKAGE__ . " onto instances is unsupported");
48 }
49  
50 # Note that the metaclass instance we started out with may have been turned
51 # into lies by the metatrait role application process, so we explicitly
52 # re-fetch it here.
53  
54 15 return find_meta($thing->name);
55 }
56  
57 21 1;
58  
59 __END__
« MethodAttributes/Role/Meta/Method/MaybeWrapped.pm ↑ Summary MethodAttributes/Role/AttrContainer/Inheritable.pm »