OpenInteract2/Action/CommonRemove.pm

filter: Statementstmt 33.8% 22 / 65 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 66.6% 6 / 9 Podpod 100% 1 / 1 totaltotal 29.0% 29 / 100 CC 10 SCAR 38.3
CC
10
Cov
26%
remove
90.0
_remove_init_param
6.0
_remove_customize
2.0
CRAP 46.1
« OpenInteract2/Manage/Package/CreatePackageFromTable.pm ↑ Summary OpenInteract2/Conversion/IniConfig.pm »
1 package OpenInteract2::Action::CommonRemove;
2  
3 # $Id: CommonRemove.pm,v 1.21 2005/03/18 04:09:49 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::CommonRemove::VERSION = sprintf("%d.%02d", q$Revision: 1.21 $ =~ /(\d+)\.(\d+)/);
13  
14 1 my ( $log );
15  
16 0 ▶sub remove {
Subroutine remove: not called CC=9 SCAR=45.0
Pod documented
17 0 my ( $self ) = @_;
18 0 $self->param( c_task => 'remove' );
19 0 $self->_remove_init_param;
20 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
21  
22 0 my $fail_task = $self->param( 'c_remove_fail_task' );
23 0 my $object = eval { $self->_common_fetch_object };
24 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
25 0 $self->add_eror_key( 'action.error.fetch_for_remove', $@ );
26 0 return $self->execute({ task => $fail_task });
27 }
28 0 ▶ unless ( $object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object) 0 0 0
29 0 $self->add_eror_key( 'action.error.not_found',
30 $self->param( 'c_id' ) );
31 0 return $self->execute({ task => $fail_task });
32 }
33 0 ▶ unless ( $object->is_saved ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object->is_saved) 0 0 0
34 0 $self->add_eror_key( 'action.error.remove_not_saved' );
35 0 return $self->execute({ task => $fail_task });
36 }
37  
38 0 $self->param( c_object => $object );
39  
40 # TODO: - assumption: SEC_LEVEL_WRITE is necessary to remove. (Probably ok.)
41  
42 0 ▶ if ( $object->{tmp_security_level} < SEC_LEVEL_WRITE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->{"tmp_security_level"} < 8) 0 0 0
43 0 ▶ my $sec_fail_task = $self->param( 'c_remove_security_fail_task' )
Condition0%0/3
$self->param('c_remove_security_fail_task') || $fail_task
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->param('c_remove_security_fail_task') || $fail_task
$self->param('c_remove_security_fail_task') $fail_task
Truth table0%0/3
A || B
A= $self->param('c_remove_security_fail_task')B= $fail_task
ABresult
1X1
011
000
44 || $fail_task;
45 0 $self->add_error_key( 'action.error.remove_security' );
46 0 return $self->execute({ task => $sec_fail_task });
47 }
48  
49 0 $self->_remove_customize;
50 0 $self->notify_observers( 'pre remove', $object );
51  
52 0 eval { $object->remove };
53 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
54 0 $self->add_error_key( 'action.error.remove', $@ );
55 0 $log->warn( "Failed to remove ", $self->param( 'c_object_class' ),
56 "with ID" , $object->id, ": $@" );
57 0 return $self->execute({ task => $fail_task });
58 }
59  
60 0 $self->notify_observers( 'post remove', $object );
61  
62 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
63 0 $self->add_status_key( 'action.status.remove', $title );
64 0 my $success_task = $self->param( 'c_remove_task' );
65 0 return $self->execute({ task => $success_task });
66 }
67  
68 1 my %DEFAULTS = (
69 c_remove_fail_task => 'common_error',
70 );
71  
72 0 ▶sub _remove_init_param {
Subroutine _remove_init_param: not called CC=2 SCAR=17.9
73 0 my ( $self ) = @_;
74 0 $self->_common_set_defaults( \%DEFAULTS );
75  
76 0 my $has_error = $self->_common_check_object_class;
77 0 $has_error += $self->_common_check_id_field;
78 0 $has_error += $self->_common_check_id;
79 0 $has_error += $self->_common_check_param(
80 qw( c_remove_fail_task c_remove_task )
81 );
82 0 ▶ if ( $has_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_error) 0 0 0
83 0 die $self->execute({ task => 'common_error' });
84 }
85 }
86  
87 ########################################
88 # OVERRIDABLE
89  
90 0 ▶sub _remove_customize { return undef }
Subroutine _remove_customize: not called CC=1 SCAR=6.9
91  
92 1 1;
93  
94 __END__
« OpenInteract2/Manage/Package/CreatePackageFromTable.pm ↑ Summary OpenInteract2/Conversion/IniConfig.pm »