| 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")
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")
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | my $name = ( ref $box eq 'HASH' ) ? $box->{name} : $box->name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | ▶ | $log->is_info && | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | $log->info( "Adding box '$name' to response" ); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | ▶ | return undef unless ( $name ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 0 | ▶ | return if ( $self->{_remove_boxes}{ $name } ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 42 | 0 | ▶ | return undef if ( $self->{_remove_boxes}{ $name } ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 50 | 0 | ▶ | push @boxes, $box unless ( $self->{_remove_boxes}{ $name } ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | $log->is_info && | ||||||||||||||||||||
| 53 | 0 | ▶ | $log->info( "Returning boxes: ", join( ', ', map { $_->{name} } @boxes ) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||
| 60 | # TODO: Should this be an error or just a log? | ||||||||||||||||||||
| 61 | 0 | ▶ | unless ( $name ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||