SIAM/Report.pm

filter: Statementstmt 68.5% 37 / 54 Branchbran 57.1% 8 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 68.4% 52 / 76 CC 9 SCAR 21.0
CC
9
Cov
66%
get_items
12.8
_manifest_attributes
2.0
BEGIN
1.0
CRAP 8.2
↑ Summary SIAM.pm »
1 package SIAM::Report;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base 'SIAM::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 SIAM::Report - Report object class
12  
13 =head1 SYNOPSIS
14  
15 my $sorted_items = $report->get_items();
16 my $item_class = $report->attr('siam.report.object_class');
17 foreach my $item (@{$sorted_items}) {
18 my $obj = $item->{'siam.report.item'};
19 my $traffic_in = $item->{'traffic.in'};
20 ...
21 }
22  
23 =head1 METHODS
24  
25 =head2 get_items
26  
27 Returns arrayref with hashes. The content of these hashes is defined by
28 the report type. Each hash has a mandatory key C<siam.report.item>
29 that points to an instantiated object.
30  
31 =cut
32  
33 sub get_items
34 1 ▶{
Subroutine get_items: called CC=9 SCAR=25.5
Pod documented
35 1 my $self = shift;
36  
37 1 my $ret = [];
38 1 my $objclass = $self->attr('siam.report.object_class');
39 1 my $content_json = $self->computable('siam.report.content');
40 1 ▶ if( not defined($content_json) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content_json) 0 1 1
41 {
42 0 $self->error('Computable siam.report.contents returned undef');
43 0 return $ret;
44 }
45
46 1 my $content = eval { decode_json($content_json) };
47 1 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
48 {
49 0 $self->error('Failed to process JSON in ' .
50 'siam.report.contents computable: ' . $@);
51 0 return $ret;
52 }
53
54 1 ▶ if( ref($content) ne 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content ne "ARRAY") 0 1 1
55 {
56 0 $self->error('siam.report.contents returned non-array data');
57 0 return $ret;
58 }
59  
60 1 foreach my $item (@{$content})
61 {
62 2 my $objid = $item->{'siam.report.item_id'};
63 2 ▶ if( not defined($objid) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $objid) 0 2 2
64 {
65 0 $self->error('siam.report.contents has array element ' .
66 'without siam.report.item_id');
67 0 next;
68 }
69
70 2 my $object = $self->instantiate_object($objclass, $objid);
71 2 ▶ if( not defined($object) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object) 0 2 2
72 {
73 0 $self->error('Cannot instantiate a report item "' . $objid . '"');
74 0 next;
75 }
76  
77 2 my $ret_item = {'siam.report.item' => $object};
78 2 ▶ while( my($key, $val) = each %{$item} )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$item;}) 2 2 4
79 {
80 2 ▶ if( $key ne 'siam.report.item_id' )
Branch: 1 branch
BranchTrueFalseTotal
if ($key ne "siam.report.item_id") 0 2 2
81 {
82 0 $ret_item->{$key} = $val;
83 }
84 }
85  
86 2 push(@{$ret}, $ret_item);
87 }
88
89 1 return $ret;
90 }
91  
92  
93
94
95 # mandatory attributes
96  
97 3 my $mandatory_attributes =
98 [ 'siam.report.name',
99 'siam.report.description',
100 'siam.report.object_class',
101 'siam.report.type',
102 'siam.report.last_updated' ];
103  
104 sub _mandatory_attributes
105 2 ▶{
Subroutine _mandatory_attributes: called CC=1 SCAR=0.0
106 2 return $mandatory_attributes;
107 }
108  
109  
110 sub _manifest_attributes
111 0 ▶{
Subroutine _manifest_attributes: not called CC=1 SCAR=6.9
112 0 my $ret = [];
113 0 push(@{$ret}, @{$mandatory_attributes},
114 0 @{ SIAM::Reports->_manifest_attributes() });
115  
116 0 return $ret;
117 }
118  
119  
120 3 1;
121  
122 # Local Variables:
123 # mode: cperl
124 # indent-tabs-mode: nil
125 # cperl-indent-level: 4
126 # cperl-continued-statement-offset: 4
127 # cperl-continued-brace-offset: -4
128 # cperl-brace-offset: 0
129 # cperl-label-offset: -2
130 # End:
↑ Summary SIAM.pm »