| 1 | package OpenInteract2::Controller; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # $Id: Controller.pm,v 1.27 2005/03/18 04:09:48 lachoy Exp $ | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 87 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 87 | ▶ | use base qw( Class::Accessor::Fast Class::Factory Class::Observable ); | ||||||||||||||||||
|
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::ActionResolver; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 87 | ▶ | use OpenInteract2::Constants qw( :log ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 87 | ▶ | use OpenInteract2::Context qw( CTX ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 87 | ▶ | use OpenInteract2::Exception qw( oi_error ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 87 | $OpenInteract2::Controller::VERSION = sprintf("%d.%02d", q$Revision: 1.27 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 87 | my ( $log ); | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 87 | my @FIELDS = qw( type generator_type initial_action ); | |||||||||||||||||||
| 18 | 87 | __PACKAGE__->mk_accessors( @FIELDS ); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 21 | 0 | my ( $class, $request, $response ) = @_; | |||||||||||||||||||
| 22 | 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")
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 0 | my $action = OpenInteract2::ActionResolver->get_action( $request ); | |||||||||||||||||||
| 25 | 0 | ▶ | unless ( $action ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 0 | oi_error "None of the action resolvers returned an action object, panic!"; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | my $impl_type = $action->controller; | |||||||||||||||||||
| 30 | 0 | my $impl_class = $class->_get_controller_implementation_class( $impl_type ); | |||||||||||||||||||
| 31 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | $log->debug( "Action '", $action->name, "' to use controller ", | ||||||||||||||||||||
| 33 | "[type: $impl_type] [class: $impl_class]" ); | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | my $self = bless( {}, $impl_class ); | |||||||||||||||||||
| 36 | 0 | $self->type( $impl_type ); | |||||||||||||||||||
| 37 | 0 | $self->initial_action( $action ); | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 0 | my $controller_info = CTX->lookup_controller_config( $impl_type ); | |||||||||||||||||||
| 40 | 0 | $self->generator_type( $controller_info->{content_generator} ); | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | $self->init; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | $self->notify_observers( 'action assigned', $action ); | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | CTX->controller( $self ); | |||||||||||||||||||
| 47 | 0 | return $self; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | ▶ | sub init { return $_[0] } | ||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | sub execute { | ||||||||||||||||||
|
Subroutine
execute: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 53 | 0 | ▶ | my $class = ref( $_[0] ) || $_[0]; | ||||||||||||||||||
|
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||
| 54 | 0 | oi_error "Subclass '$class' must override execute()"; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | ▶ | sub _get_controller_implementation_class { | ||||||||||||||||||
|
Subroutine
_get_controller_implementation_class: not called CC=6 SCAR=37.4
| |||||||||||||||||||||
| 59 | 0 | my ( $class, $controller_type ) = @_; | |||||||||||||||||||
| 60 | 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")
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | $log->debug( "Lookup controller for '$controller_type'" ); | ||||||||||||||||||||
| 64 | 0 | my $impl_class = eval { | |||||||||||||||||||
| 65 | 0 | $class->get_factory_class( $controller_type ) | |||||||||||||||||||
| 66 | }; | ||||||||||||||||||||
| 67 | 0 | my ( $error ); | |||||||||||||||||||
| 68 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 69 | 0 | $error = "Failure to get factory class for '$controller_type': $@"; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | elsif ( ! $impl_class ) { | ||||||||||||||||||||
| 72 | 0 | $error = "No implementation class defined for '$controller_type'"; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 0 | ▶ | if ( $error ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 0 | $log->error( "Cannot create controller '$controller_type': $error" ); | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | # TODO: Have this output a static (no template vars) file | ||||||||||||||||||||
| 78 | 0 | oi_error "Hey chuckie, you don't have a controller ", | |||||||||||||||||||
| 79 | "defined for type '$controller_type'"; | ||||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | 0 | return $impl_class; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | ▶ | sub factory_log { | ||||||||||||||||||
|
Subroutine
factory_log: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 85 | 0 | my ( $self, @msg ) = @_; | |||||||||||||||||||
| 86 | 0 | get_logger( LOG_ACTION )->info( @msg ); | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | ▶ | sub factory_error { | ||||||||||||||||||
|
Subroutine
factory_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 90 | 0 | my ( $self, @msg ) = @_; | |||||||||||||||||||
| 91 | 0 | get_logger( LOG_ACTION )->error( @msg ); | |||||||||||||||||||
| 92 | 0 | die @msg, "\n"; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 87 | 1; | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||