OpenInteract2/Action/CommonAdd.pm

filter: Statementstmt 28.2% 22 / 78 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 2 totaltotal 22.4% 28 / 125 CC 14 SCAR 43.3
CC
14
Cov
21%
add
156.0
display_add
6.0
_add_init_param
6.0
CRAP 76.3
« OpenInteract2/Manage/Website/CleanExpiredSessions.pm ↑ Summary OpenInteract2/Setup/CreateTemporaryLibraryDirectory.pm »
1 package OpenInteract2::Action::CommonAdd;
2  
3 # $Id: CommonAdd.pm,v 1.25 2005/03/18 04:09:48 lachoy Exp $
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base qw( OpenInteract2::Action::Common );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use SPOPS::Secure qw( SEC_LEVEL_WRITE );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 $OpenInteract2::Action::CommonAdd::VERSION = sprintf("%d.%02d", q$Revision: 1.25 $ =~ /(\d+)\.(\d+)/);
13  
14 1 my ( $log );
15  
16 0 ▶sub display_add {
Subroutine display_add: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my ( $self ) = @_;
18 0 $self->param( c_task => 'display_add' );
19 0 $self->_add_init_param;
20 0 my $object_class = $self->param( 'c_object_class' );
21  
22 # We take 'object' as a parameter in case 'add' bombs
23  
24 0 my $object = $self->param( 'c_object' );
25 0 ▶ unless ( $object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object) 0 0 0
26 0 $object = $self->param( c_object => $object_class->new );
27 }
28  
29 0 my $object_type = $self->param( 'c_object_type' );
30 0 my %template_params = ( object => $object,
31 $object_type => $object );
32 0 $self->_display_add_customize( \%template_params );
33  
34 0 my $template = $self->param( 'c_display_add_template' );
35 0 return $self->generate_content(
36 \%template_params, { name => $template } );
37 }
38  
39 0 ▶sub add {
Subroutine add: not called CC=12 SCAR=50.5
Pod undocumented
40 0 my ( $self ) = @_;
41 0 $self->param( c_task => 'add' );
42 0 $self->_add_init_param;
43 0 CTX->response->return_url( $self->param( 'c_add_return_url' ) );
44  
45 0 ▶ $log ||= get_logger( LOG_ACTION );
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
ABresult
1X1
011
000
46  
47 0 my $object_class = $self->param( 'c_object_class' );
48 0 ▶ my $object = $self->param( 'c_object' ) || $object_class->new;
Condition0%0/3
$self->param('c_object') || $object_class->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->param('c_object') || $object_class->new
$self->param('c_object') $object_class->new
Truth table0%0/3
A || B
A= $self->param('c_object')B= $object_class->new
ABresult
1X1
011
000
49  
50 # we don't want any parameter value hanging around just in case
51 # the save fails...
52  
53 0 $self->param_clear( 'c_object' );
54  
55 # Assign values from the form (specified by MY_EDIT_FIELDS,
56 # MY_EDIT_FIELDS_DATE, MY_EDIT_FIELDS_TOGGLED, ...)
57  
58 0 $self->_common_assign_properties(
59 $object, {
60 standard => scalar $self->param( 'c_add_fields' ),
61 toggled => scalar $self->param( 'c_add_fields_toggled' ),
62 boolean => scalar $self->param( 'c_add_fields_boolean' ),
63 date => scalar $self->param( 'c_add_fields_date' ),
64 datetime => scalar $self->param( 'c_add_fields_datetime' ),
65 date_format => scalar $self->param( 'c_add_date_format' ),
66 datetime_format => scalar $self->param( 'c_add_datetime_format' ),
67 } );
68  
69 # If after customizing/inspecting the object you want to bail and
70 # go somewhere else, die with content
71  
72 0 my %save_options = ();
73 0 $self->_add_customize( $object, \%save_options );
74 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("_add_customize() ran ok; notifying of 'pre add'") 0 0 0
75 $log->debug( "_add_customize() ran ok; notifying of 'pre add'" );
76  
77 0 $self->notify_observers( 'pre add', $object, \%save_options );
78 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("notification ok; saving object...") 0 0 0
79 $log->debug( "notification ok; saving object..." );
80  
81 0 eval { $object->save( \%save_options ) };
82 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
83 0 $log->warn( "Failed to create object: $@" );
84 0 $self->add_error_key( 'action.error.create', $@ );
85 0 my $fail_task = $self->param( 'c_add_fail_task' );
86 0 return $self->execute({ task => $fail_task });
87 }
88 0 ▶ $log->is_debug && $log->debug( "object saved ok" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("object saved ok") 0 0 0
89  
90 0 $self->param( c_object => $object );
91 0 $self->param( c_id => scalar $object->id );
92  
93 0 ▶ my $title = "'" . $object->object_description->{title} . "'" || 'Object';
Condition0%0/2
q['] . $object->object_description->{'title'} . q['] || 'Object'
l!l
00
MC/DC0%0/1
q['] . $object->object_description->{'title'} . q['] || 'Object'
q['] . $object->object_description->{'title'} . q[']
Truth table0%0/2
A
A= q['] . $object->object_description->{'title'} . q[']
Aresult
11
00
94 0 $self->add_status_key( 'action.status.create', $title );
95 0 ▶ $log->is_debug && $log->debug( "generated status messge ok" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("generated status messge ok") 0 0 0
96  
97 0 $self->_add_post_action( $object );
98 0 ▶ $log->is_debug && $log->debug( "_add_post_action() ran ok" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("_add_post_action() ran ok") 0 0 0
99  
100 0 $self->notify_observers( 'post add', $object );
101 0 ▶ $log->is_debug && $log->debug( "'post add' notification ok" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("'post add' notification ok") 0 0 0
102  
103 0 my $success_task = $self->param( 'c_add_task' );
104 0 ▶ $log->is_debug && $log->debug( "get task '$success_task' content" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("get task '${success_task}' content") 0 0 0
105 0 return $self->execute({ task => $success_task });
106 }
107  
108 1 my %DEFAULTS = (
109 c_add_fail_task => 'display_add',
110 );
111  
112 0 ▶sub _add_init_param {
Subroutine _add_init_param: not called CC=2 SCAR=17.9
113 0 my ( $self ) = @_;
114 0 $self->_common_set_defaults({
115 %DEFAULTS,
116 c_add_return_url => $self->create_url({ TASK => undef }),
117 });
118  
119 0 my $has_error = $self->_common_check_object_class;
120 0 $has_error +=
121 $self->_common_check_template_specified( 'c_display_add_template' );
122 0 $has_error += $self->_common_check_param( 'c_add_task' );
123 0 ▶ if ( $has_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_error) 0 0 0
124 0 die $self->execute({ task => 'common_error' });
125 }
126 }
127  
128 ########################################
129 # OVERRIDABLE
130  
131 0 ▶sub _display_add_customize { return undef }
Subroutine _display_add_customize: not called CC=1 SCAR=6.9
132 0 ▶sub _add_customize { return undef }
Subroutine _add_customize: not called CC=1 SCAR=6.9
133 0 ▶sub _add_post_action { return undef }
Subroutine _add_post_action: not called CC=1 SCAR=6.9
134  
135 1 1;
136  
137 __END__
« OpenInteract2/Manage/Website/CleanExpiredSessions.pm ↑ Summary OpenInteract2/Setup/CreateTemporaryLibraryDirectory.pm »