Elive/Entity/Report.pm

filter: Statementstmt 55.3% 31 / 56 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 55.5% 5 / 9 Podpod 100% 4 / 4 totaltotal 43.0% 40 / 93 CC 8 SCAR 24.8
CC
8
Cov
42%
BUILDARGS
30.0
insert
6.0
update
6.0
CRAP 11.9
« Elive/Entity/ParticipantList.pm ↑ Summary Elive/Entity/Participant.pm »
1 package Elive::Entity::Report;
2 3 ▶use warnings; use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 extends 'Elive::Entity';
8  
9 3 ▶use Elive::Entity::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 __PACKAGE__->entity_name('Report');
12 3 __PACKAGE__->collection_name('Reports');
13  
14 3 has 'reportId' => (is => 'rw', isa => 'Int', required => 1);
15 3 __PACKAGE__->primary_key('reportId');
16  
17 3 has 'name' => (is => 'rw', isa => 'Str',
18 documentation => 'report name');
19 3 __PACKAGE__->_alias(reportName => 'name', freeze => 1);
20  
21 3 has 'description' => (is => 'rw', isa => 'Str',
22 documentation => 'report description');
23 3 __PACKAGE__->_alias(reportDescription => 'description', freeze => 1);
24  
25 3 has 'xml' => (is => 'rw', isa => 'Str',
26 documentation => 'report content');
27 3 __PACKAGE__->_alias(reportDefinition => 'xml', freeze => 1);
28  
29 3 has 'role' => (is => 'rw', isa => 'Elive::Entity::Role',
30 documentation => 'default user role',
31 coerce => 1);
32  
33 3 has 'parentId' => (is => 'rw', isa => 'Int');
34  
35 3 has 'ownerId' => (is => 'rw', isa => 'Str');
36 3 __PACKAGE__->_alias(reportOwner => 'ownerId', freeze => 1);
37  
38 =head1 NAME
39  
40 Elive::Entity::Report - Elluminate Report entity instance class
41  
42 =head1 DESCRIPTION
43  
44 This is the entity class for server side reports. These are visible
45 on the Elluminate server under the 'Reports' tab.
46  
47 Please note that the C<list> method (C<listReports> command) does not return the body
48 of the report. The report object needs to be refetched via the C<retrieve> method.
49  
50 For example, the following code snippet exports all reports for a site:
51  
52 my $reports = Elive::Entity::Report->list;
53 my @report_ids = map {$_->reportId} @$reports;
54  
55 foreach my $report_id (@report_ids) {
56  
57 #
58 # listed objects don't have the report body, refetch them.
59 #
60  
61 my $rpt = Elive::Entity::Report->retrieve( $report_id );
62  
63 my $name = $rpt->name;
64 $name =~ s/[^\w]//g; # sanitise
65 my $export_file = "/tmp/report_${reportId}_${name}.xml";
66  
67 open (my $dump_fh, '>', $export_file)
68 or die "unable to open $export_file: $!";
69 print $dump_fh $rpt->xml;
70 close ($dump_fh);
71  
72 }
73  
74 =cut
75  
76 =head1 METHODS
77  
78 =cut
79  
80 sub BUILDARGS {
81 0 ▶ my $class = shift;
Subroutine BUILDARGS: not called CC=5 SCAR=34.0
Pod documented
82 0 my $spec = shift;
83 0 my %opt = @_;
84  
85 0 ▶ die "usage: $class->new(\$hashref)"
Branch: 1 branch
BranchTrueFalseTotal
unless Elive::Util::_reftype($spec) eq "HASH" 0 0 0
86 unless Elive::Util::_reftype($spec) eq 'HASH';
87  
88 0 my %args = %$spec;
89  
90 0 ▶ $args{ownerId} ||= do {
Condition0%0/3
$args{"ownerId"} ||= do { my $connection = $opt{"connection"} || $class->connection or die "not connected"; $connection->login->userId }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"ownerId"} ||= do { my $connection = $opt{"connection"} || $class->connection or die "not connected"; $connection->login->userId }
$args{"ownerId"} do { my $connection = $opt{"connection"} || $class->connection or die "not connected"; $connection->login->userId }
Truth table0%0/3
A ||= B
A= $args{"ownerId"}B= do { my $connection = $opt{"connection"} || $class->connection or die "not connected"; $connection->login->userId }
ABresult
1X1
011
000
91  
92 0 ▶ my $connection = $opt{connection} || $class->connection
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $opt{"connection"} || $class->connection or die "not connected" 0 0 0
Condition0%0/3
$opt{'connection'} || $class->connection
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{'connection'} || $class->connection
$opt{'connection'} $class->connection
Truth table0%0/3
A || B
A= $opt{'connection'}B= $class->connection
ABresult
1X1
011
000
93 or die "not connected";
94  
95 0 $connection->login->userId;
96 };
97  
98 0 return \%args;
99 }
100  
101 =head2 list
102  
103 my $all_reports = Elive::Entity::Report->list();
104  
105 List reports.
106  
107 Note: This command does not return the body of the report (C<xml> property).
108  
109 =cut
110  
111 =head2 retrieve
112  
113 my $report = Elive::Entity::Report->retrieve( $report_id );
114 my $report_xml = $report->xml;
115  
116 Retrieves a report, including the body of the report (C<xml> property).
117  
118 =cut
119  
120 =head2 insert
121  
122 The C<insert> method is not available for reports.
123  
124 =cut
125  
126 sub insert {
127 0 ▶ my ($class, $_spec, %opt) = @_;
Subroutine insert: not called CC=2 SCAR=17.9
Pod documented
128  
129 0 my $insert_data = $class->BUILDARGS($_spec, %opt);
130  
131 0 ▶ $opt{command} ||= 'addReport';
Condition0%0/2
$opt{"command"} ||= "addReport"
l!l
00
MC/DC0%0/1
$opt{"command"} ||= "addReport"
$opt{"command"}
Truth table0%0/2
A
A= $opt{"command"}
Aresult
11
00
132  
133 0 return $class->SUPER::insert( $class->_freeze($insert_data), %opt);
134 }
135  
136 =head2 update
137  
138 The C<update> method is not available for reports.
139  
140 =cut
141  
142 sub update {
143 0 ▶ my ($self, $_spec, %opt) = @_;
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
144  
145 0 my $update_data;
146 0 ▶ $update_data = $self->BUILDARGS($_spec, %opt)
Branch: 1 branch
BranchTrueFalseTotal
if $_spec 0 0 0
147 if $_spec;
148 #
149 # always need to supply these fields to the update command,
150 # whether or not they've actually changed.
151 #
152 0 my %changed;
153 0 @changed{$self->is_changed, 'name','description','xml', 'ownerId'} = undef;
154  
155 0 return $self->SUPER::update($update_data, %opt, changed => [keys %changed]);
156 }
157  
158 =head2 delete
159  
160 my $report = Elive::Entity::Report->retrieve( $report_id );
161 $report->delete if $report;
162  
163 Deletes a report.
164  
165 =cut
166  
167 sub delete {
168 #
169 # response seems to be returned as true/false rather than a record.
170 # hence the need to roll our own
171 #
172 0 ▶ my ($self, %opt) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
173  
174 my $som = $self->connection->call('deleteReport'
175 0 => %{$self->_freeze({reportId => $self->reportId})
176 });
177  
178 0 my $results = $self->_get_results($som, $self->connection);
179 #
180 # this command responds with true/false, rather than a report record.
181 #
182 0 ▶ my $deleted = $results && $results->[0];
Condition0%0/3
$results && $results->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$results && $results->[0]
$results $results->[0]
Truth table0%0/3
A && B
A= $resultsB= $results->[0]
ABresult
0X0
100
111
183  
184 0 return $self->_deleted($deleted);
185 }
186  
187 3 1;
« Elive/Entity/ParticipantList.pm ↑ Summary Elive/Entity/Participant.pm »