blib/lib/MooseX/Attribute/Localize.pm

filter: Statementstmt 83.5% 56 / 67 Branchbran 54.5% 12 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 1 totaltotal 77.2% 78 / 101 CC 19 SCAR 16.1
CC
19
Cov
76%
__ANON__
8.1
local_bar
8.1
set_local_bar
8.1
CRAP 5.0
↑ Summary
1 package MooseX::Attribute::Localize;
2 3 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: localize attribute values within a scope
4 3 $MooseX::Attribute::Localize::VERSION = '0.1.2';
5 3 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 has _value_stack => (
8 traits => [ qw/ Array / ],
9 is => 'ro',
10 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
11 3 handles => {
12 _push_value => 'push',
13 _pop_value => 'pop',
14 },
15 );
16  
17 3 has localize_push => ( is => 'ro', predicate => 'has_localize_push' );
18 3 has localize_pop => ( is => 'ro', predicate => 'has_localize_pop' );
19  
20 3 ▶before '_canonicalize_handles' => sub {
Subroutine __ANON__: called CC=3 SCAR=12.6
21 3 my( $self ) = @_;
22  
23 3 my $handles = $self->handles;
24  
25 0 ▶ $_ = sub {
Subroutine __ANON__: not called CC=5 SCAR=20.9
Subroutine set_local_bar: called CC=5 SCAR=20.9
26 0 my $object = shift;
27  
28 0 my $attr = $object->meta->get_attribute( $self->name );
29  
30 0 my ( $old ) = $attr->_push_value( $attr->get_value($object) );
31
32 0 $attr->clear_value($object);
33  
34 0 my $new_value;
35  
36 0 ▶ $attr->set_value( $object, $new_value = shift ) if @_;
Branch: 2 branches
BranchTrueFalseTotal
if @_ 0 0 0
if @_ 4 1 5
37  
38 0 ▶ warn "localize called in void context is a no-op\n"
Branch: 2 branches
BranchTrueFalseTotal
unless defined wantarray 0 0 0
unless defined wantarray 0 5 5
39 unless defined wantarray;
40  
41 0 ▶ if( my $method = $attr->localize_push ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $method = $attr->localize_push) 0 0 0
if (my $method = $attr->localize_push) 2 3 5
42 my $func = ref $method ? $method :
43 0 ▶ sub { my $self = shift; $self->$method(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.5
Branch: 2 branches
BranchTrueFalseTotal
ref $method ? : 0 0 0
ref $method ? : 1 1 2
44 0 $func->( $object, $new_value, $old, $attr );
45 }
46  
47 0 return MooseX::Attribute::Localize::Sentinel->new(
48 attribute => $attr,
49 object => $object,
50 );
51 3 } for grep { $_ eq 'localize' } values %$handles;
52  
53 12 ▶ $_ = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
54 12 my $object = shift;
55  
56 12 my $attr = $object->meta->get_attribute( $self->name );
57  
58 12 my @values = reverse @{ $attr->_value_stack };
59 12 ▶ unshift @values, $attr->get_value($object) if $attr->has_value($object);
Branch: 1 branch
BranchTrueFalseTotal
if $attr->has_value($object) 12 0 12
60  
61 12 return @values;
62  
63 3 } for grep { $_ eq 'localize_stack' } values %$handles;
64  
65 3 };
66  
67 {
68 package MooseX::Attribute::Localize::Sentinel;
69 3 our $AUTHORITY = 'cpan:YANICK';
70 3 $MooseX::Attribute::Localize::Sentinel::VERSION = '0.1.2';
71 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 3 has [qw/ attribute object /] => ( is => 'ro' );
74  
75 5 ▶ sub DEMOLISH {
Subroutine DEMOLISH: called CC=3 SCAR=11.0
Pod undocumented
76 5 my $self = shift;
77 5 my $old_value = $self->attribute->get_value( $self->object );
78 5 my $new_value = $self->attribute->_pop_value;
79 5 $self->attribute->set_value( $self->object, $new_value );
80 5 ▶ if( my $method = $self->attribute->localize_pop ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $self->attribute->localize_pop) 2 3 5
81 1 ▶ my $func = ref $method ? $method : sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
82 1 my $self = shift;
83 1 $self->$method(@_);
84 2 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
ref $method ? : 1 1 2
85 2 $func->($self->object,$new_value,$old_value,$self->attribute);
86 }
87 }
88 }
89  
90 {
91 3 package Moose::Meta::Attribute::Custom::Trait::Localize;
92 3 our $AUTHORITY = 'cpan:YANICK';
93 3 $Moose::Meta::Attribute::Custom::Trait::Localize::VERSION = '0.1.2';
94 2 ▶sub register_implementation { 'MooseX::Attribute::Localize' }
Subroutine register_implementation: called CC=1 SCAR=0.0
95  
96 }
97  
98 3 1;
99  
100 __END__
↑ Summary