OpenInteract2/Setup/InitializeContentGenerators.pm

filter: Statementstmt 48.9% 24 / 49 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 3 totaltotal 42.1% 32 / 76 CC 7 SCAR 32.8
CC
7
Cov
39%
execute
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 26.7
« OpenInteract2/Response/LWP.pm ↑ Summary OpenInteract2/Manage.pm »
1 package OpenInteract2::Setup::InitializeContentGenerators;
2  
3 # $Id: InitializeContentGenerators.pm,v 1.3 2005/03/18 04:09:51 lachoy Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use base qw( OpenInteract2::Setup );
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 );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 87 ▶use OpenInteract2::ContentGenerator;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 87 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 87 $OpenInteract2::Setup::InitializeContentGenerators::VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
13  
14 87 my ( $log );
15  
16 87 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod undocumented
17 87 return 'initialize content generators';
18 }
19  
20 1 ▶sub get_dependencies {
Subroutine get_dependencies: called CC=1 SCAR=0.0
Pod undocumented
21 1 return ( 'read packages' );
22 }
23  
24 0 ▶sub execute {
Subroutine execute: not called CC=7 SCAR=40.3
Pod undocumented
25 0 my ( $self, $ctx ) = @_;
26 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
27  
28 0 $log->info( "Initializing all content generators" );
29 0 my $all_generator_info = $ctx->lookup_content_generator_config;
30  
31 BIG_GENERATOR:
32 0 ▶ while ( my ( $name, $generator_data ) = each %{ $all_generator_info } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$all_generator_info;}) 0 0 0
33 0 ▶ next if ( $name eq 'default' );
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "default" 0 0 0
34 0 my $generator_class = $generator_data->{class};
35 0 ▶ unless ( $generator_class ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($generator_class) 0 0 0
36 0 $log->error( "Cannot use generator '$name': no class ",
37 "specified in the generator configuration ",
38 "key 'class'" );
39 0 next BIG_GENERATOR;
40 }
41 0 my $full_name = "[Name: $name] [Class: $generator_class]";
42 0 $log->info( "Trying to require and initialize $full_name" );
43 0 eval "require $generator_class";
44 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
45 0 $log->error( "Failed to require generator $full_name: $@" );
46 0 next BIG_GENERATOR;
47 }
48 0 my ( $generator );
49 0 eval {
50 0 $generator = $generator_class->new( $name, $generator_class );
51 0 $generator->initialize( $generator_data );
52 };
53 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
54 0 $log->error( "Require ok, but cannot initialize generator ",
55 "$full_name. Error: $@" );
56 }
57 else {
58 0 $log->info( "Successfully required and initialized ",
59 "generator $full_name" );
60 0 OpenInteract2::ContentGenerator->add_generator( $name, $generator );
61 }
62 }
63 }
64  
65 87 OpenInteract2::Setup->register_factory_type( get_name() => __PACKAGE__ );
66  
67 87 1;
68  
69 __END__
« OpenInteract2/Response/LWP.pm ↑ Summary OpenInteract2/Manage.pm »