OpenInteract2/Controller/ManageBoxes.pm

filter: Statementstmt 36.0% 18 / 50 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 45.4% 5 / 11 Podpod 0.0% 0 / 6 totaltotal 22.7% 23 / 101 CC 15 SCAR 29.3
CC
15
Cov
22%
add_box
42.0
get_boxes
20.0
remove_box
20.0
CRAP 18.7
« OpenInteract2/Setup/ReadSPOPSConfig.pm ↑ Summary OpenInteract2/SessionManager/File.pm »
1 package OpenInteract2::Controller::ManageBoxes;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 $OpenInteract2::Controller::MangeBoxes::VERSION = sprintf("%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/);
10  
11 2 my ( $log );
12  
13 # Box might be an action object or just a hashref, but it must have
14 # 'name' defined
15  
16 0 ▶sub init_boxes {
Subroutine init_boxes: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my ( $self ) = @_;
18 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
19  
20 0 $self->{_boxes} = {};
21 0 $self->{_remove_boxes} = {};
22 }
23  
24 0 ▶sub add_box {
Subroutine add_box: not called CC=6 SCAR=37.4
Pod undocumented
25 0 my ( $self, $box ) = @_;
26 0 ▶ return undef unless ( ref $box );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $box 0 0 0
27  
28 0 ▶ my $name = ( ref $box eq 'HASH' ) ? $box->{name} : $box->name;
Branch: 1 branch
BranchTrueFalseTotal
ref $box eq 'HASH' ? : 0 0 0
29 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Adding box '${name}' to response") 0 0 0
30 $log->info( "Adding box '$name' to response" );
31  
32 0 ▶ return undef unless ( $name );
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
33 0 ▶ return if ( $self->{_remove_boxes}{ $name } );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_remove_boxes"}{$name} 0 0 0
34  
35 0 $self->{_boxes}{ $name } = $box;
36 0 return $box;
37 }
38  
39 0 ▶sub get_box {
Subroutine get_box: not called CC=3 SCAR=24.8
Pod undocumented
40 0 my ( $self, $name ) = @_;
41 0 ▶ return undef unless ( $name );
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
42 0 ▶ return undef if ( $self->{_remove_boxes}{ $name } );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_remove_boxes"}{$name} 0 0 0
43 0 return $self->{_boxes}{ $name };
44 }
45  
46 0 ▶sub get_boxes {
Subroutine get_boxes: not called CC=4 SCAR=30.0
Pod undocumented
47 0 my ( $self ) = @_;
48 0 my @boxes = ();
49 0 ▶ while ( my ( $name, $box ) = each %{ $self->{_boxes} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"_boxes"};}) 0 0 0
50 0 ▶ push @boxes, $box unless ( $self->{_remove_boxes}{ $name } );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_remove_boxes"}{$name} 0 0 0
51 }
52 $log->is_info &&
53 0 ▶ $log->info( "Returning boxes: ", join( ', ', map { $_->{name} } @boxes ) );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Returning boxes: ", join(", ", map({$_->{"name"};} @boxes))) 0 0 0
54 0 return \@boxes;
55 }
56  
57 0 ▶sub remove_box {
Subroutine remove_box: not called CC=4 SCAR=30.0
Pod undocumented
58 0 my ( $self, $name ) = @_;
59 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
60 # TODO: Should this be an error or just a log?
61 0 ▶ unless ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 0 0 0
62 0 oi_error "Must specify box name when removing box";
63 }
64 $log->is_info &&
65 0 ▶ $log->info( "Marking box '$name' as removed from response" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Marking box '${name}' as removed from response") 0 0 0
66 0 $self->{_remove_boxes}{ $name }++;
67 }
68  
69 0 ▶sub is_box_removed {
Subroutine is_box_removed: not called CC=1 SCAR=6.9
Pod undocumented
70 0 my ( $self, $name ) = @_;
71 0 return $self->{_remove_boxes}{ $name };
72 }
73  
74 2 1;
75  
76 __END__
« OpenInteract2/Setup/ReadSPOPSConfig.pm ↑ Summary OpenInteract2/SessionManager/File.pm »