GX/Meta/Attribute/String.pm

filter: Statementstmt 96.4% 54 / 56 Branchbran 85.7% 12 / 14 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 10 / 10 Podpod 33.3% 1 / 3 totaltotal 89.0% 81 / 91 CC 10 SCAR 16.0
CC
10
Cov
92%
create_accessor
9.2
__ANON__
2.0
BEGIN
1.0
CRAP 5.0
« GX/Renderer.pm ↑ Summary GX/Meta/Package.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Meta/Attribute/String.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Meta::Attribute::String;
7  
8 107 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 107 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 107 ▶use base 'GX::Meta::Attribute';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 107 ▶use GX::Meta::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 # ----------------------------------------------------------------------------------------------------------------------
17 # Constants
18 # ----------------------------------------------------------------------------------------------------------------------
19  
20 107 ▶use constant TYPE_CONSTRAINT => sub { defined $_[1] && ! ref $_[1] };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] and not ref $_[1] 302 17 319
21  
22  
23 # ----------------------------------------------------------------------------------------------------------------------
24 # Public methods
25 # ----------------------------------------------------------------------------------------------------------------------
26  
27 1 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
28  
29 1 return 'String';
30  
31 }
32  
33  
34 # ----------------------------------------------------------------------------------------------------------------------
35 # Public methods
36 # ----------------------------------------------------------------------------------------------------------------------
37  
38 453 ▶sub create_accessor {
Subroutine create_accessor: called CC=9 SCAR=22.1
Pod undocumented
39  
40 453 my $self = shift;
41 453 my %args = @_;
42  
43 453 ▶ my $name = $args{'name'} // $self->name;
Condition33%1/3
$args{"name"} // $self->name
l!l&&r!l&&!r
45300
MC/DC0%0/2
$args{"name"} // $self->name
$args{"name"} $self->name
Truth table33%1/3
A // B
A= $args{"name"}B= $self->name
ABresult
1X1
011
000
44 453 ▶ my $type = $args{'type'} // 'default';
Condition100%2/2
$args{"type"} // "default"
l!l
43320
MC/DC100%1/1
$args{"type"} // "default"
$args{"type"}
Truth table100%2/2
A
A= $args{"type"}
Aresult
11
00
45  
46 453 my $data = {};
47 453 my $code = [];
48 453 my $vars = {};
49  
50 453 push @$code,
51 'package ' . ref( $self ) . ';',
52 'sub {';
53  
54 453 $self->_inline_accessor_prologue( $data, $code, $vars );
55  
56 453 ▶ if ( $type eq 'default' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type eq 'default') { } 27 426 453
elsif ($type eq 'get') { } 314 112 426
elsif ($type eq 'set') { } 98 14 112
elsif ($type eq 'clear') { } 7 7 14
elsif ($type eq 'length') { } 7 0 7
57  
58 27 push @$code, 'if ( @_ > 1 ) {';
59 27 $self->_inline_set_value( $data, $code, $vars, '$_[1]' );
60 27 push @$code, '} else {';
61 27 $self->_inline_prepare_slot( $data, $code, $vars );
62 27 push @$code, '}';
63  
64 27 $self->_inline_return_slot( $data, $code, $vars );
65  
66 }
67 elsif ( $type eq 'get' ) {
68  
69 314 $self->_inline_prepare_slot( $data, $code, $vars );
70  
71 314 $self->_inline_return_slot( $data, $code, $vars );
72  
73 }
74 elsif ( $type eq 'set' ) {
75  
76 98 $self->_inline_set_value( $data, $code, $vars, '$_[1]' );
77  
78 98 push @$code, 'return;';
79  
80 }
81 elsif ( $type eq 'clear' ) {
82  
83 7 $self->_inline_delete_slot( $data, $code, $vars );
84  
85 7 push @$code, 'return;';
86  
87 }
88 elsif ( $type eq 'length' ) {
89  
90 7 $self->_inline_prepare_slot( $data, $code, $vars );
91  
92 7 push @$code, 'return length ' . $data->{'slot'} . ';';
93  
94 }
95 else {
96 0 complain "Unsupported accessor type: \"$type\"";
97 }
98  
99 453 push @$code, '}';
100  
101 453 my $accessor = eval {
102 453 GX::Meta::Accessor->new(
103 attribute => $self,
104 name => $name,
105 type => $type,
106 code => GX::Meta::Util::eval_code( $code, $vars )
107 );
108 };
109  
110 453 ▶ if ( ! $accessor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($accessor) 0 453 453
111 0 complain $@;
112 }
113  
114 453 return $accessor;
115  
116 }
117  
118 3 ▶sub native_value {
Subroutine native_value: called CC=1 SCAR=0.0
Pod undocumented
119  
120 3 return '';
121  
122 }
123  
124  
125 # ----------------------------------------------------------------------------------------------------------------------
126 # Private methods
127 # ----------------------------------------------------------------------------------------------------------------------
128  
129 272 ▶sub _inline_set_slot_to_native_value {
Subroutine _inline_set_slot_to_native_value: called CC=1 SCAR=0.0
130  
131 272 my $self = shift;
132 272 my $data = shift;
133 272 my $code = shift;
134 272 my $vars = shift;
135  
136 272 $self->_inline_assign_to_slot( $data, $code, $vars, '\'\'' );
137  
138 272 return;
139  
140 }
141  
142  
143 107 1;
144  
145 __END__
« GX/Renderer.pm ↑ Summary GX/Meta/Package.pm »