| 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")
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")
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | my ( $url ); | |||||||||||||||||||
| 36 | 0 | my @resolvers = (); | |||||||||||||||||||
| 37 | 0 | ▶ | if ( scalar @other ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 0 | ▶ | unless ( ref $other[0] ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 44 | 0 | @resolvers = $class->get_all_resolvers; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | ▶ | $url ||= $request->url_relative; | ||||||||||||||||||
|
Condition0%0/3
$url ||= $request->url_relative
MC/DC0%0/2
$url ||= $request->url_relative
$url
$request->url_relative
Truth table0%0/3
A ||= B
A= $urlB= $request->url_relative
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 54 | 0 | $log->warn( "Resolver ", ref( $r ), " threw an ", | |||||||||||||||||||
| 55 | "exception ($@); continuing with others..." ); | ||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | 0 | ▶ | last if ( $action ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 68 | 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")
| |||||||||||||||||||||
| 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
MC/DC0%0/2
ref $item || $item
ref $item
$item
Truth table0%0/3
A || B
A= ref $itemB= $item
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||