OpenInteract2/ActionResolver.pm

filter: Statementstmt 40.3% 25 / 62 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 50.0% 7 / 14 Podpod 0.0% 0 / 6 totaltotal 28.0% 32 / 114 CC 13 SCAR 35.3
CC
13
Cov
29%
get_action
90.0
assign_additional_params_from_url
12.0
get_all_resolvers
6.0
CRAP 34.0
« OpenInteract2/URL.pm ↑ Summary OpenInteract2/Response.pm »
1 package OpenInteract2::ActionResolver;
2  
3 # $Id: ActionResolver.pm,v 1.3 2005/03/02 15:30:38 lachoy Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use base qw( Class::Factory );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 87 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use OpenInteract2::Constants qw( LOG_ACTION );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 87 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 87 ▶use OpenInteract2::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 87 ▶use OpenInteract2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 87 my ( $log );
14  
15 87 $OpenInteract2::ActionResolver::VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
16  
17 0 ▶sub resolver_sort {
Subroutine resolver_sort: not called CC=1 SCAR=6.9
Pod undocumented
18 0 return $a->get_order <=> $b->get_order;
19 }
20  
21 0 ▶sub get_all_resolvers {
Subroutine get_all_resolvers: not called CC=2 SCAR=17.9
Pod undocumented
22 0 my ( $class ) = @_;
23 0 my @all_resolver_types = $class->get_registered_types();
24 0 my @resolvers = ();
25 0 foreach my $type ( @all_resolver_types ) {
26 0 push @resolvers, $class->new( $type );
27 }
28 0 return sort resolver_sort @resolvers;
29 }
30  
31 0 ▶sub get_action {
Subroutine get_action: not called CC=9 SCAR=45.0
Pod undocumented
32 0 my ( $class, $request, @other ) = @_;
33 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
34  
35 0 my ( $url );
36 0 my @resolvers = ();
37 0 ▶ if ( scalar @other ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @other) 0 0 0
38 0 ▶ unless ( ref $other[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $other[0]) 0 0 0
39 0 $url = OpenInteract2::URL->parse_absolute_to_relative( shift @other );
40 }
41 0 @resolvers = @other;
42 }
43 0 ▶ unless ( scalar @resolvers ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @resolvers) 0 0 0
44 0 @resolvers = $class->get_all_resolvers;
45 }
46  
47 0 ▶ $url ||= $request->url_relative;
Condition0%0/3
$url ||= $request->url_relative
l!l&&r!l&&!r
000
MC/DC0%0/2
$url ||= $request->url_relative
$url $request->url_relative
Truth table0%0/3
A ||= B
A= $urlB= $request->url_relative
ABresult
1X1
011
000
48 0 $log->info( "Sending URL '$url' to ", scalar( @resolvers ), " ",
49 "action resolvers" );
50 0 my ( $action );
51 0 foreach my $r ( @resolvers ) {
52 0 $action = eval { $r->resolve( $request, $url ) };
53 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
54 0 $log->warn( "Resolver ", ref( $r ), " threw an ",
55 "exception ($@); continuing with others..." );
56 }
57 0 ▶ last if ( $action );
Branch: 1 branch
BranchTrueFalseTotal
if $action 0 0 0
58 }
59 0 return $action;
60 }
61  
62 ########################################
63 # OBJECT METHODS
64  
65 0 ▶sub assign_additional_params_from_url {
Subroutine assign_additional_params_from_url: not called CC=3 SCAR=24.8
Pod undocumented
66 0 my ( $self, $request, @params ) = @_;
67 0 ▶ if ( scalar @params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @params) 0 0 0
68 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
69 0 $log->info( "Assigning additional URL parameters: ",
70 join( ', ', @params ) );
71 0 $request->param_url_additional( @params );
72 }
73 }
74  
75  
76  
77 ########################################
78 # SUBCLASSES
79  
80 0 ▶sub resolve { _must_implement( 'resolve', @_ ) }
Subroutine resolve: not called CC=1 SCAR=6.9
Pod undocumented
81 0 ▶sub get_order { return 5 }
Subroutine get_order: not called CC=1 SCAR=6.9
Pod undocumented
82  
83 0 ▶sub _must_implement {
Subroutine _must_implement: not called CC=2 SCAR=17.9
84 0 my ( $method, $item ) = @_;
85 0 ▶ my $class = ref( $item ) || $item;
Condition0%0/3
ref $item || $item
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $item || $item
ref $item $item
Truth table0%0/3
A || B
A= ref $itemB= $item
ABresult
1X1
011
000
86 0 oi_error "Class '$class' must implement method '$method'";
87 }
88  
89 87 OpenInteract2::Util->find_factory_subclasses(
90 'OpenInteract2::ActionResolver', @INC
91 );
92  
93 87 1;
94  
95 __END__
« OpenInteract2/URL.pm ↑ Summary OpenInteract2/Response.pm »