Attributes/Trait/Method/Accessor.pm

filter: Statementstmt 53.6% 22 / 41 Branchbran 25.0% 2 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 61.5% 8 / 13 Podpod n/a totaltotal 51.6% 32 / 62 CC 7 SCAR 9.9
CC
7
Cov
49%
__ANON__
6.0
mark_one_clean
6.0
__ANON__
3.0
CRAP 2.7
« Attributes/Trait/Attribute.pm ↑ Summary Attributes/Trait/Role/Application/ToInstance.pm »
1 #
2 # This file is part of MooseX-TrackDirty-Attributes
3 #
4 # This software is Copyright (c) 2011 by Chris Weyl.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 package MooseX::TrackDirty::Attributes::Trait::Method::Accessor;
11 8 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 $MooseX::TrackDirty::Attributes::Trait::Method::Accessor::AUTHORITY = 'cpan:RSRCHBOY';
13 }
14 8 $MooseX::TrackDirty::Attributes::Trait::Method::Accessor::VERSION = '2.003';
15 # ABSTRACT: Track dirtied attributes
16  
17 8 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # debugging
21 #use Smart::Comments '###', '####';
22  
23 1 ▶sub _generate_cleaner_method {
Subroutine _generate_cleaner_method: called CC=1 SCAR=1.7
24 1 my $self = shift;
25 1 my $attr = $self->associated_attribute;
26  
27 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
28 0 ▶ confess "Clearer accessors take no arguments"
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 0 0
29 if @_ > 1;
30 0 $attr->mark_clean($_[0]);
31 1 };
32 }
33  
34 0 ▶sub _generate_cleaner_method_inline {
Subroutine _generate_cleaner_method_inline: not called CC=1 SCAR=6.9
35 0 my $self = shift;
36 0 my $attr = $self->associated_attribute;
37  
38 return try {
39 0 $self->_compile_code([
40 'sub {',
41 'if (@_ > 1) {',
42 # XXX: this is a hack, but our error stuff is terrible
43 $self->_inline_throw_error(
44 '"Clearer accessors take no arguments"',
45 'data => \@_'
46 ) . ';',
47 '}',
48 $attr->_inline_mark_clean('$_[0]'),
49 '}',
50 ]);
51 }
52 0 catch {
53 0 confess "Could not generate inline clearer because : $_";
54 };
55 }
56  
57 2 ▶sub _generate_original_value_method {
Subroutine _generate_original_value_method: called CC=1 SCAR=0.9
58 2 my $self = shift;
59 2 my $attr = $self->associated_attribute;
60  
61 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=10.9
Subroutine original_value_of_one: called CC=2 SCAR=10.9
62 0 ▶ confess "Cannot assign a value to a read-only accessor"
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 0 0 0
if @_ > 1 0 44 44
63 if @_ > 1;
64 0 $attr->is_dirty_get($_[0]);
65 2 };
66 }
67  
68 0 ▶sub _generate_original_value_method_inline {
Subroutine _generate_original_value_method_inline: not called CC=1 SCAR=6.9
69 0 my $self = shift;
70 0 my $attr = $self->associated_attribute;
71  
72 return try {
73 0 $self->_compile_code([
74 'sub {',
75 'if (@_ > 1) {',
76 # XXX: this is a hack, but our error stuff is terrible
77 $self->_inline_throw_error(
78 '"Cannot assign a value to a read-only accessor"',
79 'data => \@_'
80 ) . ';',
81 '}',
82 $attr->_inline_is_dirty_get('$_[0]'),
83 '}',
84 ]);
85 }
86 0 catch {
87 0 confess "Could not generate inline original_value because : $_";
88 };
89 }
90  
91 9 ▶sub _generate_is_dirty_method {
Subroutine _generate_is_dirty_method: called CC=1 SCAR=0.0
92 9 my $self = shift;
93 9 my $attr = $self->associated_attribute;
94  
95 12 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
96 12 ▶ confess "Cannot assign a value to a read-only accessor"
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 12 12
97 if @_ > 1;
98 12 $attr->is_dirty_instance($_[0]);
99 9 };
100 }
101  
102 0 ▶sub _generate_is_dirty_method_inline {
Subroutine _generate_is_dirty_method_inline: not called CC=1 SCAR=6.9
103 0 my $self = shift;
104 0 my $attr = $self->associated_attribute;
105  
106 return try {
107 0 $self->_compile_code([
108 'sub {',
109 'if (@_ > 1) {',
110 # XXX: this is a hack, but our error stuff is terrible
111 $self->_inline_throw_error(
112 '"Cannot assign a value to a read-only accessor"',
113 'data => \@_'
114 ) . ';',
115 '}',
116 $attr->_inline_is_dirty_instance('$_[0]'),
117 '}',
118 ]);
119 }
120 0 catch {
121 0 confess "Could not generate inline is_dirty because : $_";
122 };
123 }
124  
125 8 !!42;
126  
127 __END__
« Attributes/Trait/Attribute.pm ↑ Summary Attributes/Trait/Role/Application/ToInstance.pm »