lib/Reaction/UI/ViewPort/Object.pm

filter: Statementstmt 73.7% 143 / 194 Branchbran 47.3% 18 / 38 Conditioncond 36.8% 7 / 19 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 60.9% 25 / 41 Podpod 100% 2 / 2 totaltotal 64.1% 195 / 304 CC 30 SCAR 19.8
CC
30
Cov
67%
get_builder_for
25.4
_build_containers
7.0
_build_computed_field_order
6.5
CRAP 7.2
« lib/Reaction/InterfaceModel/Action/User/SetPassword.pm ↑ Summary lib/Reaction/UI/WidgetClass/_OVER.pm »
1 package Reaction::UI::ViewPort::Object;
2  
3 5 ▶use Reaction::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use aliased 'Reaction::UI::ViewPort::Field::Text';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use aliased 'Reaction::UI::ViewPort::Field::Number';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use aliased 'Reaction::UI::ViewPort::Field::Integer';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use aliased 'Reaction::UI::ViewPort::Field::Boolean';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use aliased 'Reaction::UI::ViewPort::Field::String';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use aliased 'Reaction::UI::ViewPort::Field::DateTime';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use aliased 'Reaction::UI::ViewPort::Field::RelatedObject';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use aliased 'Reaction::UI::ViewPort::Field::Array';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use aliased 'Reaction::UI::ViewPort::Field::Collection';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use aliased 'Reaction::UI::ViewPort::Field::File';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use aliased 'Reaction::UI::ViewPort::Field::Container';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 5 ▶use aliased 'Reaction::InterfaceModel::Object' => 'IM_Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 ▶use MooseX::Types::Moose qw/ArrayRef HashRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 5 ▶use namespace::clean -except => [ qw(meta) ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 extends 'Reaction::UI::ViewPort';
23  
24 5 with 'Reaction::UI::ViewPort::Role::Actions';
25  
26 #everything is read only right now. Later I can make somethings read-write
27 #but first I need to figure out what depends on what so we can have decent triggers
28 5 has model => (is => 'ro', isa => IM_Object, required => 1);
29 5 has fields => (is => 'ro', isa => ArrayRef, lazy_build => 1);
30  
31 5 has field_args => (is => 'rw');
32 5 has field_order => (is => 'ro', isa => ArrayRef);
33  
34 5 has builder_cache => (is => 'ro', isa => HashRef, lazy_build => 1);
35 5 has excluded_fields => (is => 'ro', isa => ArrayRef, lazy_build => 1);
36 5 has included_fields => (is => 'ro', isa => ArrayRef, lazy_build => 1);
37 5 has computed_field_order => (is => 'ro', isa => ArrayRef, lazy_build => 1);
38  
39 5 has containers => ( is => 'ro', isa => ArrayRef, lazy_build => 1);
40 5 has container_layouts => ( is => 'rw', isa => ArrayRef );
41  
42 3 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=8.1
Pod documented
43 3 my ($self, $args) = @_;
44 3 ▶ if( my $field_args = delete $args->{Field} ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $field_args = delete $args->{"Field"}) 0 3 3
45 0 $self->field_args( $field_args );
46 }
47 }
48  
49 3 ▶sub _build_builder_cache { {} }
Subroutine _build_builder_cache: called CC=1 SCAR=0.0
50 3 ▶sub _build_excluded_fields { [] }
Subroutine _build_excluded_fields: called CC=1 SCAR=0.0
51 3 ▶sub _build_included_fields { [] }
Subroutine _build_included_fields: called CC=1 SCAR=0.0
52  
53 3 ▶sub _build_containers {
Subroutine _build_containers: called CC=6 SCAR=19.4
54 3 my $self = shift;
55  
56 3 my @container_layouts;
57 3 ▶ if( $self->has_container_layouts ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_container_layouts) 0 3 3
58 #make sure we don't accidentally modify the original
59 0 @container_layouts = map { {%$_} }@{ $self->container_layouts };
60 } #we should always have a '_' container;
61 0 ▶ unless (grep {$_->{name} eq '_'} @container_layouts ){
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->{"name"} eq "_";} @container_layouts) 3 0 3
62 3 unshift(@container_layouts, {name => '_'});
63 }
64  
65 3 my %fields;
66 3 my $ordered_field_names = $self->computed_field_order;
67 3 @fields{ @$ordered_field_names } = @{ $self->fields };
68  
69 3 my %containers;
70 my @container_order;
71 3 for my $layout ( @container_layouts ){
72 3 my @container_fields;
73 3 my $name = $layout->{name};
74 3 push(@container_order, $name);
75 3 ▶ if( my $field_names = delete $layout->{fields} ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $field_names = delete $layout->{"fields"}) 0 3 3
76 0 map{ push(@container_fields, $_) } grep { defined }
77 0 map { delete $fields{$_} } @$field_names;
78 }
79 3 $containers{$name} = Container->new(
80 ctx => $self->ctx,
81 location => join( '-', $self->location, 'container', $name ),
82 fields => \@container_fields,
83 %$layout,
84 );
85 }
86 3 ▶ if( keys %fields ){
Branch: 1 branch
BranchTrueFalseTotal
if (keys %fields) 3 0 3
87 3 my @leftovers = grep { exists $fields{$_} } @$ordered_field_names;
88 3 push(@{ $containers{_}->fields }, @fields{@leftovers} );
89 }
90  
91 #only return containers with at least one field
92 3 return [ grep { scalar(@{ $_->fields }) } @containers{@container_order} ];
93 }
94  
95 3 ▶sub _build_fields {
Subroutine _build_fields: called CC=6 SCAR=18.5
96 3 my ($self) = @_;
97 3 my $obj = $self->model;
98 3 ▶ my $args = $self->has_field_args ? $self->field_args : {};
Branch: 1 branch
BranchTrueFalseTotal
$self->has_field_args ? : 0 3 3
99 3 my @fields;
100 3 my %param_attrs = map { $_->name => $_ } $obj->parameter_attributes;
101 3 for my $field_name (@{ $self->computed_field_order }) {
102 12 my $attr = $param_attrs{$field_name};
103 12 ▶ my $meth = $self->builder_cache->{$field_name} ||= $self->get_builder_for($attr);
Condition33%1/3
$self->builder_cache->{$field_name} ||= $self->get_builder_for($attr)
l!l&&r!l&&!r
0120
MC/DC0%0/2
$self->builder_cache->{$field_name} ||= $self->get_builder_for($attr)
$self->builder_cache->{$field_name} $self->get_builder_for($attr)
Truth table33%1/3
A ||= B
A= $self->builder_cache->{$field_name}B= $self->get_builder_for($attr)
ABresult
1X1
011
000
104 12 ▶ my $field = $self->$meth($attr, ($args->{$field_name} || {}));
Condition50%1/2
$args->{$field_name} || {}
l!l
012
MC/DC0%0/1
$args->{$field_name} || {}
$args->{$field_name}
Truth table50%1/2
A
A= $args->{$field_name}
Aresult
11
00
105 12 ▶ next unless $field;
Branch: 1 branch
BranchTrueFalseTotal
unless $field 0 12 12
106 12 push(@fields, $field);
107 }
108 3 return \@fields;
109 }
110  
111 3 ▶sub _build_computed_field_order {
Subroutine _build_computed_field_order: called CC=5 SCAR=18.7
112 3 my ($self) = @_;
113 0 my %excluded = map { $_ => undef } @{ $self->excluded_fields };
114 0 my %included = map { $_ => undef } @{ $self->included_fields };
115 #treat _$field_name as private and exclude fields with no reader
116 my @names = grep { $_ !~ /^_/ && (!%included || exists( $included{$_}) )
117 12 ▶ && !exists($excluded{$_}) } map { $_->name }
Condition33%3/9
!($_ =~ /^_/) && (!%included || exists $included{$_}) && !exists $excluded{$_}
!ll&&!rl&&r
0012
not $_ =~ /^_/ and !%included || exists $included{$_}
!ll&&!rl&&r
0012
not %included or exists $included{$_}
l!l&&r!l&&!r
1200
MC/DC0%0/4
!($_ =~ /^_/) && (!%included || exists $included{$_}) && !exists $excluded{$_}
not $_ =~ /^_/ not %included exists $included{$_} !exists $excluded{$_}
Truth table16%1/6
not(A) and not(B) or C && not(D)
A= not $_ =~ /^_/B= not %includedC= exists $included{$_}D= !exists $excluded{$_}
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
118 3 grep { defined $_->get_read_method } $self->model->parameter_attributes;
119 3 ▶ return $self->sort_by_spec($self->field_order || [], \@names);
Condition50%1/2
$self->field_order || []
l!l
03
MC/DC0%0/1
$self->field_order || []
$self->field_order
Truth table50%1/2
A
A= $self->field_order
Aresult
11
00
120 }
121  
122 2 ▶override child_event_sinks => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
123 2 return ( @{shift->fields}, super());
124 5 };
125  
126 #candidate for shared role!
127 12 ▶sub get_builder_for {
Subroutine get_builder_for: called CC=13 SCAR=32.3
Pod documented
128 12 my ($self, $attr) = @_;
129 12 my $attr_name = $attr->name;
130 12 my $builder = "_build_fields_for_name_${attr_name}";
131 12 ▶ return $builder if $self->can($builder);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($builder) 0 12 12
132 12 ▶ if ($attr->has_type_constraint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->has_type_constraint) { } 12 0 12
133 12 my $constraint = $attr->type_constraint;
134 12 my $base_name = $constraint->name;
135 12 my $tried_isa = 0;
136 12 my @tried;
137 12 ▶ CONSTRAINT: while (defined($constraint)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $constraint) 15 0 15
138 15 my $name = $constraint->name;
139 15 ▶ $name = $attr->_isa_metadata if($name eq '__ANON__');
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "__ANON__" 0 15 15
140 15 ▶ if (eval { $name->can('meta') } && !$tried_isa++) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $name->can("meta") } } and not $tried_isa++) 0 15 15
Condition33%1/3
eval { do { $name->can("meta") } } and not $tried_isa++
!ll&&!rl&&r
1500
MC/DC0%0/2
eval { do { $name->can("meta") } } and not $tried_isa++
eval { do { $name->can("meta") } } not $tried_isa++
Truth table33%1/3
A and not(B)
A= eval { do { $name->can("meta") } }B= not $tried_isa++
ABresult
0X0
100
111
141 0 foreach my $class ($name->meta->class_precedence_list) {
142 0 push(@tried, $class);
143 0 my $mangled_name = $class;
144 0 $mangled_name =~ s/:+/_/g;
145 0 my $builder = "_build_fields_for_type_${mangled_name}";
146 0 ▶ return $builder if $self->can($builder);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($builder) 0 0 0
147 }
148 }
149 15 ▶ if (defined($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 15 0 15
150 15 push(@tried, $name);
151 15 ▶ unless (defined($base_name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_name) 0 15 15
152 0 $base_name = "(anon subtype of ${name})";
153 }
154 15 my $mangled_name = $name;
155 15 $mangled_name =~ s/:+/_/g;
156 15 my $builder = "_build_fields_for_type_${mangled_name}";
157 15 ▶ return $builder if $self->can($builder);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($builder) 12 3 15
158 }
159 3 $constraint = $constraint->parent;
160 }
161 0 ▶ if (!defined($constraint)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $constraint) 0 0 0
162 0 confess "Can't build field ${attr_name} of type ${base_name} without "
163 ."$builder method or _build_fields_for_type_<type> method "
164 ."for type or any supertype (tried ".join(', ', @tried).")";
165 }
166 } else {
167 0 confess "Can't build field ${attr} without $builder method or type constraint";
168 }
169 }
170  
171 12 ▶sub _build_simple_field {
Subroutine _build_simple_field: called CC=3 SCAR=11.2
172 12 my ($self, %args) = @_;
173 12 my $class = delete $args{class};
174 12 ▶ confess("Can not build simple field without a viewport class")
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 12 12
175 unless $class;
176 confess("Can not build simple field without attribute")
177 12 ▶ unless defined $args{attribute};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"attribute"} 0 12 12
178  
179 12 my $field_name = $args{attribute}->name;
180 12 return $class->new(
181 ctx => $self->ctx,
182 model => $self->model,
183 location => join('-', $self->location, 'field', $field_name),
184 %args
185 );
186 }
187  
188 0 ▶sub _build_fields_for_type_Num {
Subroutine _build_fields_for_type_Num: not called CC=1 SCAR=6.9
189 0 my ($self, $attr, $args) = @_;
190 0 $self->_build_simple_field(attribute => $attr, class => Number, %$args);
191 }
192  
193 0 ▶sub _build_fields_for_type_Int {
Subroutine _build_fields_for_type_Int: not called CC=1 SCAR=6.9
194 0 my ($self, $attr, $args) = @_;
195 #XXX
196 0 $self->_build_simple_field(attribute => $attr, class => Integer, %$args);
197 }
198  
199 0 ▶sub _build_fields_for_type_Bool {
Subroutine _build_fields_for_type_Bool: not called CC=1 SCAR=6.9
200 0 my ($self, $attr, $args) = @_;
201 0 $self->_build_simple_field(attribute => $attr, class => Boolean, %$args);
202 }
203  
204 #XXX
205 0 ▶sub _build_fields_for_type_Reaction_Types_Core_Password { return };
Subroutine _build_fields_for_type_Reaction_Types_Core_Password: not called CC=1 SCAR=6.9
206  
207 0 ▶sub _build_fields_for_type_Str {
Subroutine _build_fields_for_type_Str: not called CC=1 SCAR=6.9
208 0 my ($self, $attr, $args) = @_;
209 #XXX
210 0 $self->_build_simple_field(attribute => $attr, class => String, %$args);
211 }
212  
213 0 ▶sub _build_fields_for_type_Reaction_Types_Core_SimpleStr {
Subroutine _build_fields_for_type_Reaction_Types_Core_SimpleStr: not called CC=1 SCAR=6.9
214 0 my ($self, $attr, $args) = @_;
215 0 $self->_build_simple_field(attribute => $attr, class => String, %$args);
216 }
217  
218 0 ▶sub _build_fields_for_type_Reaction_Types_DateTime_DateTime {
Subroutine _build_fields_for_type_Reaction_Types_DateTime_DateTime: not called CC=1 SCAR=6.9
219 0 my ($self, $attr, $args) = @_;
220 0 $self->_build_simple_field(attribute => $attr, class => DateTime, %$args);
221 }
222  
223 0 ▶sub _build_fields_for_type_Enum {
Subroutine _build_fields_for_type_Enum: not called CC=1 SCAR=6.9
224 0 my ($self, $attr, $args) = @_;
225 #XXX
226 0 $self->_build_simple_field(attribute => $attr, class => String, %$args);
227 }
228  
229 0 ▶sub _build_fields_for_type_ArrayRef {
Subroutine _build_fields_for_type_ArrayRef: not called CC=1 SCAR=6.9
230 0 my ($self, $attr, $args) = @_;
231 0 $self->_build_simple_field(attribute => $attr, class => Array, %$args);
232 }
233  
234 0 ▶sub _build_fields_for_type_Reaction_Types_File_File {
Subroutine _build_fields_for_type_Reaction_Types_File_File: not called CC=1 SCAR=6.9
235 0 my ($self, $attr, $args) = @_;
236 0 $self->_build_simple_field(attribute => $attr, class => File, %$args);
237 }
238  
239 0 ▶sub _build_fields_for_type_Reaction_InterfaceModel_Object {
Subroutine _build_fields_for_type_Reaction_InterfaceModel_Object: not called CC=1 SCAR=6.9
240 0 my ($self, $attr, $args) = @_;
241 #XXX
242 0 $self->_build_simple_field(attribute => $attr, class => RelatedObject, %$args);
243 }
244  
245 0 ▶sub _build_fields_for_type_Reaction_InterfaceModel_Collection {
Subroutine _build_fields_for_type_Reaction_InterfaceModel_Collection: not called CC=1 SCAR=6.9
246 0 my ($self, $attr, $args) = @_;
247 0 $self->_build_simple_field(attribute => $attr, class => Collection, %$args);
248 }
249  
250 0 ▶sub _build_fields_for_type_MooseX_Types_Common_String_SimpleStr {
Subroutine _build_fields_for_type_MooseX_Types_Common_String_SimpleStr: not called CC=1 SCAR=6.9
251 0 my ($self, $attr, $args) = @_;
252 0 $self->_build_simple_field(attribute => $attr, class => String, %$args);
253 }
254  
255 0 ▶sub _build_fields_for_type_MooseX_Types_Common_String_Password {
Subroutine _build_fields_for_type_MooseX_Types_Common_String_Password: not called CC=1 SCAR=6.9
256 0 return;
257 }
258  
259 0 ▶sub _build_fields_for_type_MooseX_Types_DateTime_DateTime {
Subroutine _build_fields_for_type_MooseX_Types_DateTime_DateTime: not called CC=1 SCAR=6.9
260 0 my ($self, $attr, $args) = @_;
261 0 $self->_build_simple_field(attribute => $attr, class => DateTime, %$args);
262 }
263  
264 0 ▶sub _build_fields_for_type_DateTime {
Subroutine _build_fields_for_type_DateTime: not called CC=1 SCAR=6.9
265 0 my ($self, $attr, $args) = @_;
266 0 $self->_build_simple_field(attribute => $attr, class => DateTime, %$args);
267 }
268  
269 5 __PACKAGE__->meta->make_immutable;
270  
271 5 1;
272  
273 __END__;
« lib/Reaction/InterfaceModel/Action/User/SetPassword.pm ↑ Summary lib/Reaction/UI/WidgetClass/_OVER.pm »