OpenInteract2/SPOPS.pm

filter: Statementstmt 16.3% 28 / 171 Branchbran 0.0% 0 / 72 Conditioncond 0.0% 0 / 61 MC/DCmcdc 0.0% 0 / 38 Subroutinesub 29.6% 8 / 27 Podpod 0.0% 0 / 19 totaltotal 9.2% 36 / 388 CC 60 SCAR 50.9
CC
60
Cov
9%
object_description
506.0
notify
132.0
log_action_enter
72.0
CRAP 163.0
« OpenInteract2/Action/Common.pm ↑ Summary OpenInteract2/TT2/Context.pm »
1 package OpenInteract2::SPOPS;
2  
3 # $Id: SPOPS.pm,v 1.31 2005/03/18 03:34:27 lachoy Exp $
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Digest::MD5 qw( md5_hex );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use OpenInteract2::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use OpenInteract2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 $OpenInteract2::SPOPS::VERSION = sprintf("%d.%02d", q$Revision: 1.31 $ =~ /(\d+)\.(\d+)/);
15  
16 3 my ( $log );
17  
18 # This is not public, look away, look away!
19 3 $OpenInteract2::SPOPS::TRACKING_DISABLED = 0;
20  
21 ########################################
22 # OBJECT DESCRIPTION
23  
24 # overrides implementation from SPOPS.pm
25  
26 0 ▶sub object_description {
Subroutine object_description: not called CC=22 SCAR=62.3
Pod undocumented
27 0 my ( $self ) = @_;
28 0 ▶ $log ||= get_logger( LOG_SPOPS );
Condition0%0/3
$log ||= get_logger("OI2.SPOPS")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.SPOPS")
$log get_logger("OI2.SPOPS")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.SPOPS")
ABresult
1X1
011
000
29  
30 0 my $config = $self->CONFIG;
31 0 my $object_type = $config->{object_name};
32 0 ▶ my $title_info = $config->{title} || $config->{name};
Condition0%0/3
$config->{'title'} || $config->{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{'title'} || $config->{'name'}
$config->{'title'} $config->{'name'}
Truth table0%0/3
A || B
A= $config->{'title'}B= $config->{'name'}
ABresult
1X1
011
000
33 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Describing SPOPS object '${object_type}' '${title_info}'") 0 0 0
34 $log->debug( "Describing SPOPS object '$object_type' '$title_info'" );
35 0 my $title = '';
36 0 ▶ if ( exists $self->{ $title_info } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{$title_info}) { } 0 0 0
elsif ($title_info) { } 0 0 0
37 0 $title = $self->{ $title_info };
38 }
39 elsif ( $title_info ) {
40 0 $title = eval { $self->$title_info() };
41 }
42 0 ▶ $title ||= 'Cannot find name';
Condition0%0/2
$title ||= "Cannot find name"
l!l
00
MC/DC0%0/1
$title ||= "Cannot find name"
$title
Truth table0%0/2
A
A= $title
Aresult
11
00
43  
44 0 my $u = OpenInteract2::URL->new();
45 0 my $oid = $self->id;
46 0 my $id_field = $self->id_field;
47 0 ▶ $log->is_debug && $log->debug( "Describe: '$oid' '$id_field'" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Describe: '${oid}' '${id_field}'") 0 0 0
48 0 my ( $url, $url_edit );
49 0 ▶ my $inf = $config->{display} || {};
Condition0%0/2
$config->{'display'} || {}
l!l
00
MC/DC0%0/1
$config->{'display'} || {}
$config->{'display'}
Truth table0%0/2
A
A= $config->{'display'}
Aresult
11
00
50 0 my @url_param_values = ();
51 0 ▶ if ( $inf->{URL_PARAMS} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inf->{"URL_PARAMS"}) 0 0 0
52 my @url_params = ( ref $inf->{URL_PARAMS} )
53 0 ? @{ $inf->{URL_PARAMS} }
54 0 ▶ : ( $inf->{URL_PARAMS} );
Branch: 1 branch
BranchTrueFalseTotal
ref $inf->{'URL_PARAMS'} ? : 0 0 0
55 0 @url_param_values = map { eval { $self->$_() } } @url_params;
56 }
57 0 ▶ if ( $inf->{ACTION} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inf->{'ACTION'}) { } 0 0 0
58 0 ▶ if ( $inf->{TASK} and @url_param_values ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($inf->{'TASK'} and @url_param_values) { } 0 0 0
elsif ($inf->{'TASK'}) { } 0 0 0
Condition0%0/3
$inf->{"TASK"} and @url_param_values
!ll&&!rl&&r
000
MC/DC0%0/2
$inf->{"TASK"} and @url_param_values
$inf->{"TASK"} @url_param_values
Truth table0%0/3
A and B
A= $inf->{"TASK"}B= @url_param_values
ABresult
0X0
100
111
59 $url = $u->create_from_action(
60 $inf->{ACTION}, $inf->{TASK},
61 0 { URL_PARAMS => \@url_param_values }
62 );
63 }
64 elsif ( $inf->{TASK} ) {
65 $url = $u->create_from_action(
66 $inf->{ACTION}, $inf->{TASK},
67 0 { $id_field => $oid }
68 );
69 }
70 0 ▶ if ( $inf->{TASK_EDIT} and @url_param_values ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($inf->{'TASK_EDIT'} and @url_param_values) { } 0 0 0
elsif ($inf->{'TASK_EDIT'}) { } 0 0 0
Condition0%0/3
$inf->{"TASK_EDIT"} and @url_param_values
!ll&&!rl&&r
000
MC/DC0%0/2
$inf->{"TASK_EDIT"} and @url_param_values
$inf->{"TASK_EDIT"} @url_param_values
Truth table0%0/3
A and B
A= $inf->{"TASK_EDIT"}B= @url_param_values
ABresult
0X0
100
111
71 $url_edit = $u->create_from_action(
72 $inf->{ACTION}, $inf->{TASK_EDIT},
73 0 { URL_PARAMS => \@url_param_values }
74 );
75 }
76 elsif ( $inf->{TASK_EDIT} ) {
77 $url_edit = $u->create_from_action(
78 $inf->{ACTION}, $inf->{TASK_EDIT},
79 0 { $id_field => $oid }
80 );
81 }
82  
83 }
84 else {
85 0 ▶ if ( $inf->{url} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inf->{"url"}) 0 0 0
86 0 $url = "$inf->{url}?" . $id_field . '=' . $oid;
87 }
88 0 ▶ if ( $inf->{url_edit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inf->{'url_edit'}) { } 0 0 0
89 0 $url_edit = "$inf->{url_edit}?" . $id_field . '=' . $oid;
90 }
91 else {
92 0 $url_edit = "$inf->{url}?edit=1;" . $id_field . '=' . $oid;
93 }
94 }
95 0 my ( $object_date );
96 0 ▶ if ( my $date_field = $inf->{date} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $date_field = $inf->{"date"}) 0 0 0
97 0 $object_date = $self->$date_field();
98 }
99 $log->is_debug &&
100 0 ▶ $log->debug( "Describe: '$url', '$url_edit', '$object_date'" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Describe: '${url}', '${url_edit}', '${object_date}'") 0 0 0
101 return {
102 class => ref $self,
103 object_id => $oid,
104 oid => $oid, # backwards compatibility
105 security => $self->{tmp_security_level},
106 0 id_field => $id_field,
107 name => $object_type,
108 title => $title,
109 date => $object_date,
110 url => $url,
111 url_edit => $url_edit,
112 };
113 }
114  
115  
116 ########################################
117 # OBJECT TRACK METHODS
118  
119 # Just a wrapper for log_action_enter, although we make sure that the
120 # action is allowed before doing it.
121  
122 0 ▶sub log_action {
Subroutine log_action: not called CC=3 SCAR=24.8
Pod undocumented
123 0 my ( $self, $action, $id ) = @_;
124 0 ▶ return 1 unless ( $self->CONFIG->{track}{ $action } );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->CONFIG->{"track"}{$action} 0 0 0
125 0 ▶ return 1 if ( $OpenInteract2::SPOPS::TRACKING_DISABLED );
Branch: 1 branch
BranchTrueFalseTotal
if $OpenInteract2::SPOPS::TRACKING_DISABLED 0 0 0
126 0 return $self->log_action_enter( $action, $id );
127 }
128  
129  
130 # Log the object, the action (create, update, remove), who did
131 # the action and when it was done.
132 #
133 # Note that you can pass the uid in directly to override the current user
134  
135 0 ▶sub log_action_enter {
Subroutine log_action_enter: not called CC=8 SCAR=42.8
Pod undocumented
136 0 my ( $self, $action, $id, $uid ) = @_;
137 0 ▶ $log ||= get_logger( LOG_SPOPS );
Condition0%0/3
$log ||= get_logger("OI2.SPOPS")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.SPOPS")
$log get_logger("OI2.SPOPS")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.SPOPS")
ABresult
1X1
011
000
138  
139 0 my $req = CTX->request;
140 0 my $log_msg = 'no log message';
141  
142 # This looks weird but it's here for when you run actions not
143 # logged in as user and outside the bounds of a request/response
144 # lifecycle...
145  
146 0 ▶ if ( UNIVERSAL::isa( $req, 'OpenInteract2::Request' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($req, 'OpenInteract2::Request')) { } 0 0 0
147 0 ▶ $uid ||= $req->auth_user_id;
Condition0%0/3
$uid ||= $req->auth_user_id
l!l&&r!l&&!r
000
MC/DC0%0/2
$uid ||= $req->auth_user_id
$uid $req->auth_user_id
Truth table0%0/3
A ||= B
A= $uidB= $req->auth_user_id
ABresult
1X1
011
000
148 0 $log_msg = $req->param( '_log_message' );
149 }
150 else {
151 0 ▶ $uid ||= CTX->lookup_default_object_id( 'superuser' );
Condition0%0/3
$uid ||= CTX()->lookup_default_object_id("superuser")
l!l&&r!l&&!r
000
MC/DC0%0/2
$uid ||= CTX()->lookup_default_object_id("superuser")
$uid CTX()->lookup_default_object_id("superuser")
Truth table0%0/3
A ||= B
A= $uidB= CTX()->lookup_default_object_id("superuser")
ABresult
1X1
011
000
152 }
153 0 my $now = DateTime->now;
154 0 ▶ my $class = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
155 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Log [$action] [$class] [$id] by [$uid] [$now]") 0 0 0
156 $log->debug( "Log [$action] [$class] [$id] by [$uid] [$now]" );
157 0 my $object_action = eval {
158 0 CTX->lookup_object( 'object_action' )
159 ->new({ class => $class,
160 object_id => $id,
161 action => $action,
162 action_by => $uid,
163 action_on => $now,
164 notes => $log_msg })
165 ->save()
166 };
167 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
168 0 $log->error( "Log entry failed: $@" );
169 0 return undef;
170 }
171 0 return 1;
172 }
173  
174  
175 # Retrieve the user who created a particular object
176  
177 0 ▶sub fetch_creator {
Subroutine fetch_creator: not called CC=6 SCAR=37.4
Pod undocumented
178 0 my ( $self ) = @_;
179 0 ▶ $log ||= get_logger( LOG_SPOPS );
Condition0%0/3
$log ||= get_logger("OI2.SPOPS")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.SPOPS")
$log get_logger("OI2.SPOPS")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.SPOPS")
ABresult
1X1
011
000
180  
181 # Bail if it's not an already-existing object
182  
183 0 ▶ return undef unless ( ref $self and $self->id );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self and $self->id 0 0 0
Condition0%0/3
ref $self and $self->id
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self and $self->id
ref $self $self->id
Truth table0%0/3
A and B
A= ref $selfB= $self->id
ABresult
0X0
100
111
184 0 my $track = eval {
185 0 CTX->lookup_object( 'object_action' )
186 ->fetch_object_creation( $self )
187 };
188 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
189 0 $log->error( "Failed to retrieve object creator(s): $@" );
190 0 return undef;
191 }
192 0 my $creator = eval { $track->action_by_user };
193 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
194 0 $log->error( "Error fetching creator: $@" );
195 }
196 0 return $creator;
197 }
198  
199  
200 # Return 1 if the user represented by $uid is a creator
201 # of an object (or the superuser), undef if not
202  
203 0 ▶sub is_creator {
Subroutine is_creator: not called CC=4 SCAR=30.0
Pod undocumented
204 0 my ( $self, $uid ) = @_;
205 0 my $req = CTX->request;
206 0 ▶ $uid ||= $req->auth_user_id;
Condition0%0/3
$uid ||= $req->auth_user_id
l!l&&r!l&&!r
000
MC/DC0%0/2
$uid ||= $req->auth_user_id
$uid $req->auth_user_id
Truth table0%0/3
A ||= B
A= $uidB= $req->auth_user_id
ABresult
1X1
011
000
207 0 ▶ return undef unless ( $uid );
Branch: 1 branch
BranchTrueFalseTotal
unless $uid 0 0 0
208  
209 # the great and powerful superuser sees all
210  
211 0 ▶ return 1 if ( $uid eq CTX->lookup_default_object_id( 'superuser' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $uid eq CTX()->lookup_default_object_id("superuser") 0 0 0
212  
213 0 my $creator = $self->fetch_creator;
214 0 return ( $creator->id eq $uid );
215 }
216  
217 # TODO: Update this to just return the object...
218 #
219 # Retrieve an arrayref of arrayrefs where item 0 is the uid
220 # of the user who last did the update and item 1 is the
221 # date of the update
222  
223 0 ▶sub fetch_updates {
Subroutine fetch_updates: not called CC=7 SCAR=40.3
Pod undocumented
224 0 my ( $self, $opt ) = @_;
225 0 ▶ $log ||= get_logger( LOG_SPOPS );
Condition0%0/3
$log ||= get_logger("OI2.SPOPS")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.SPOPS")
$log get_logger("OI2.SPOPS")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.SPOPS")
ABresult
1X1
011
000
226  
227 # Bail if it's not an already-saved object
228  
229 0 ▶ return [] unless ( ref $self and $self->id );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self and $self->id 0 0 0
Condition0%0/3
ref $self and $self->id
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self and $self->id
ref $self $self->id
Truth table0%0/3
A and B
A= ref $selfB= $self->id
ABresult
0X0
100
111
230 0 ▶ my $limit = ( $opt eq 'last' ) ? '1' : int( $opt );
Branch: 1 branch
BranchTrueFalseTotal
$opt eq 'last' ? : 0 0 0
231 0 my $updates = eval {
232 0 CTX->lookup_object( 'object_action' )
233 ->fetch_actions( $self,
234 { limit => $limit,
235 column_group => 'base' } )
236 };
237 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
238 0 $log->error( "Cannot retrieve object updates: $@" );
239 0 return undef;
240 }
241 $log->is_debug &&
242 0 ▶ $log->debug( "Data from updates:\n", CTX->dump( $updates ) );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Data from updates:\n", CTX()->dump($updates)) 0 0 0
243 0 return [ map { [ $_->{action_by}, $_->{action_on} ] } @{ $updates } ];
244 }
245  
246  
247 ########################################
248 # SECURITY
249  
250 # Override method in SPOPS::Secure since we already know the
251 # user/group information from the context
252  
253 0 ▶sub get_security_scopes {
Subroutine get_security_scopes: not called CC=2 SCAR=17.9
Pod undocumented
254 0 my ( $self, $p ) = @_;
255 0 my $req = CTX->request;
256 0 ▶ if ( $req ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req) { } 0 0 0
257 0 return ( $req->auth_user, $req->auth_group );
258 }
259 else {
260 0 return ( undef, [] );
261 }
262 }
263  
264  
265  
266 # Let SPOPS::Secure know what the IDs are for the superuser and
267 # supergroup
268  
269 0 ▶sub get_superuser_id {
Subroutine get_superuser_id: not called CC=1 SCAR=6.9
Pod undocumented
270 0 return CTX->lookup_default_object_id( 'superuser' );
271 }
272  
273 0 ▶sub get_supergroup_id {
Subroutine get_supergroup_id: not called CC=1 SCAR=6.9
Pod undocumented
274 0 return CTX->lookup_default_object_id( 'supergroup' );
275 }
276  
277 ########################################
278 # DATASOURCE
279  
280 0 ▶sub global_datasource_handle {
Subroutine global_datasource_handle: not called CC=3 SCAR=24.8
Pod undocumented
281 0 my ( $self, $connect_key ) = @_;
282 $connect_key ||= $self->CONFIG->{datasource}
283 0 ▶ || CTX->lookup_default_datasource_name;
Condition0%0/6
$connect_key ||= $self->CONFIG->{"datasource"} || CTX()->lookup_default_datasource_name
l!l&&r!l&&!r
000
$self->CONFIG->{'datasource'} || CTX()->lookup_default_datasource_name
l!l&&r!l&&!r
000
MC/DC0%0/3
$connect_key ||= $self->CONFIG->{"datasource"} || CTX()->lookup_default_datasource_name
$connect_key $self->CONFIG->{'datasource'} CTX()->lookup_default_datasource_name
Truth table0%0/4
A ||= B || C
A= $connect_keyB= $self->CONFIG->{'datasource'}C= CTX()->lookup_default_datasource_name
ABCresult
1XX1
01X1
0011
0000
284 0 return CTX->datasource( $connect_key );
285 }
286  
287  
288 ########################################
289 # GLOBAL OBJECTS/CLASSES
290  
291 # These are used so that subclasses (and other classes in the
292 # inheritance hierarchy, particularly within SPOPS) are able to have
293 # access to the various objects and resources
294  
295 0 ▶sub global_cache { return CTX->cache }
Subroutine global_cache: not called CC=1 SCAR=6.9
Pod undocumented
296  
297 # ugh .. is this used
298 0 ▶sub global_config { return CTX->server_config }
Subroutine global_config: not called CC=1 SCAR=6.9
Pod undocumented
299  
300 # Is this right? Is this needed?
301 0 ▶sub global_secure_class { return CTX->lookup_object( 'secure' ) }
Subroutine global_secure_class: not called CC=1 SCAR=6.9
Pod undocumented
302  
303 0 ▶sub global_security_object_class { return CTX->lookup_object( 'security' ) }
Subroutine global_security_object_class: not called CC=1 SCAR=6.9
Pod undocumented
304 0 ▶sub global_user_class { return CTX->lookup_object( 'user' ) }
Subroutine global_user_class: not called CC=1 SCAR=6.9
Pod undocumented
305 0 ▶sub global_group_class { return CTX->lookup_object( 'group' ) }
Subroutine global_group_class: not called CC=1 SCAR=6.9
Pod undocumented
306  
307 0 ▶sub global_user_current {
Subroutine global_user_current: not called CC=2 SCAR=17.9
Pod undocumented
308 0 my $req = CTX->request;
309 0 ▶ return ( $req ) ? CTX->request->auth_user : undef;
Branch: 1 branch
BranchTrueFalseTotal
$req ? : 0 0 0
310 }
311  
312 0 ▶sub global_group_current {
Subroutine global_group_current: not called CC=2 SCAR=17.9
Pod undocumented
313 0 my $req = CTX->request;
314 0 ▶ return ( $req ) ? CTX->request->auth_group : [];
Branch: 1 branch
BranchTrueFalseTotal
$req ? : 0 0 0
315 }
316  
317  
318 ########################################
319 # OTHER METHODS
320  
321 # Send an email with one or more objects as the body.
322  
323 0 ▶sub notify {
Subroutine notify: not called CC=11 SCAR=48.8
Pod undocumented
324 0 my ( $item, $p ) = @_;
325 0 ▶ $log ||= get_logger( LOG_SPOPS );
Condition0%0/3
$log ||= get_logger("OI2.SPOPS")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.SPOPS")
$log get_logger("OI2.SPOPS")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.SPOPS")
ABresult
1X1
011
000
326  
327 0 my $req = CTX->request;
328 0 ▶ $p->{object} ||= [];
Condition0%0/2
$p->{"object"} ||= []
l!l
00
MC/DC0%0/1
$p->{"object"} ||= []
$p->{"object"}
Truth table0%0/2
A
A= $p->{"object"}
Aresult
11
00
329  
330 # If we weren't given any objects and we were called by
331 # a class instead of an object
332  
333 0 ▶ return undef unless ( ref $item or scalar @{ $p->{object} } );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item or scalar @{$p->{"object"};} 0 0 0
Condition0%0/2
ref $item or scalar @{$p->{"object"};}
l!l
00
MC/DC0%0/1
ref $item or scalar @{$p->{"object"};}
ref $item
Truth table0%0/2
A
A= ref $item
Aresult
11
00
334  
335 # If we were just called by an object, make it our message
336  
337 0 ▶ push @{ $p->{object} }, $item unless ( scalar @{ $p->{object} } );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$p->{"object"};} 0 0 0
338 0 my $num_objects = scalar @{ $p->{object} };
339 0 ▶ my $subject = $p->{subject} || "Object notification: $num_objects objects in mail";
Condition0%0/2
$p->{'subject'} || "Object notification: $num_objects objects in mail"
l!l
00
MC/DC0%0/1
$p->{'subject'} || "Object notification: $num_objects objects in mail"
$p->{'subject'}
Truth table0%0/2
A
A= $p->{'subject'}
Aresult
11
00
340 0 my $separator = '=' x 25;
341 0 ▶ my $msg = ( $p->{notes} ) ?
Branch: 1 branch
BranchTrueFalseTotal
$p->{'notes'} ? : 0 0 0
342 join( "\n", 'Notes', "$separator$p->{notes}", $separator, "\n" ) : '';
343 0 foreach my $obj ( @{ $p->{object} } ) {
344 0 my $info = $obj->object_description;
345 0 my $object_url = join( '', 'http://', $req->server_name, $info->{url} );
346 0 $msg .= <<OBJECT;
347 Begin $info->{name} object
348 $separator
349 0 @{[ $obj->as_string ]}
350  
351 View this object at: $object_url
352 $separator
353 End $p->{name} object
354  
355 OBJECT
356 }
357 my $from_email = $p->{email_from} ||
358 0 ▶ CTX->lookup_mail_config->{admin_email};
Condition0%0/3
$p->{'email_from'} || CTX()->lookup_mail_config->{'admin_email'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{'email_from'} || CTX()->lookup_mail_config->{'admin_email'}
$p->{'email_from'} CTX()->lookup_mail_config->{'admin_email'}
Truth table0%0/3
A || B
A= $p->{'email_from'}B= CTX()->lookup_mail_config->{'admin_email'}
ABresult
1X1
011
000
359 0 eval {
360 OpenInteract2::Util->send_email({ to => $p->{email},
361 0 from => $from_email,
362 subject => $subject,
363 message => $msg });
364 };
365 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
366 0 $log->error( "Failed to send email: $@" );
367 0 return undef;
368 }
369 0 return 1;
370 }
371  
372 3 1;
373  
374 __END__
« OpenInteract2/Action/Common.pm ↑ Summary OpenInteract2/TT2/Context.pm »