OpenInteract2/Manage/Website/PackageCheckExportInstall.pm

filter: Statementstmt 42.4% 28 / 66 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 9 / 15 Podpod 0.0% 0 / 6 totaltotal 35.9% 37 / 103 CC 11 SCAR 27.3
CC
11
Cov
34%
run_task
42.0
_run_subtask
20.0
validate_param
12.0
CRAP 15.3
« OpenInteract2/Setup/ReadActionTable.pm ↑ Summary OpenInteract2/Manage/Website/RemovePackage.pm »
1 package OpenInteract2::Manage::Website::PackageCheckExportInstall;
2  
3 # $Id: PackageCheckExportInstall.pm,v 1.8 2005/03/18 04:09:50 lachoy Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use base qw( OpenInteract2::Manage::Website );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 87 ▶use Cwd qw( cwd );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use File::Spec::Functions qw( catfile );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 87 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 87 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 87 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 87 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 87 $OpenInteract2::Manage::Website::PackageCheckExportInstall::VERSION = sprintf("%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/);
15  
16 87 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod undocumented
17 87 return 'package_all';
18 }
19  
20 0 ▶sub get_brief_description {
Subroutine get_brief_description: not called CC=1 SCAR=6.9
Pod undocumented
21 0 return "Check, export and install a package";
22 }
23  
24 0 ▶sub get_parameters {
Subroutine get_parameters: not called CC=1 SCAR=6.9
Pod undocumented
25 0 my ( $self ) = @_;
26 return {
27 0 website_dir => $self->_get_website_dir_param,
28 package_dir => {
29 description => 'Package to check, export and install (only one)',
30 is_required => 'yes',
31 is_multivalued => 'no',
32 default => cwd(),
33 },
34 };
35 }
36  
37 0 ▶sub validate_param {
Subroutine validate_param: not called CC=3 SCAR=24.8
Pod undocumented
38 0 my ( $self, $param_name, $param_value ) = @_;
39 0 ▶ if ( $param_name eq 'package_dir' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param_name eq "package_dir") 0 0 0
40 0 my $package_ini_file = catfile( $param_value, 'package.ini' );
41 0 ▶ unless ( -f $package_ini_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $package_ini_file) 0 0 0
42 0 return "Directory does not appear to be a package";
43 }
44 }
45 0 return $self->SUPER::validate_param( $param_name, $param_value );
46 }
47  
48 # no-op, but don't remove otherwise the 'check_package' task will
49 # check the wrong files because our parent uses this to create the
50 # context -- see OIN-147 for sample error
51 0 ▶sub setup_task {}
Subroutine setup_task: not called CC=1 SCAR=0.0
Pod undocumented
52  
53 0 ▶sub run_task {
Subroutine run_task: not called CC=6 SCAR=37.4
Pod undocumented
54 0 my ( $self ) = @_;
55  
56 0 my ( $is_ok, $subtask );
57 0 ( $is_ok, $subtask ) = $self->_run_subtask( 'check_package' );
58 0 ▶ return unless ( $is_ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $is_ok 0 0 0
59 0 $self->_ok( 'check package',
60 'No errors in package' );
61  
62 0 ( $is_ok, $subtask ) = $self->_run_subtask( 'export_package' );
63 0 ▶ return unless ( $is_ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $is_ok 0 0 0
64 0 $self->_ok( 'export package',
65 'Package written to archive' );
66 0 my ( $package_file );
67 0 foreach my $status ( $subtask->get_status ) {
68 0 ▶ if ( $status->{message} =~ /^Exported package [\w\.\-]+ to/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status->{"message"} =~ /^Exported package [\w\.\-]+ to/) 0 0 0
69 0 $package_file = $status->{filename};
70 }
71 }
72  
73 0 warn "Package file set to '$package_file'\n";
74  
75 0 ( $is_ok, $subtask ) = $self->_run_subtask(
76 'install_package', package_file => $package_file );
77 0 ▶ return unless ( $is_ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $is_ok 0 0 0
78 0 $self->_ok( 'install package',
79 'Package installed to website' );
80 }
81  
82 0 ▶sub _run_subtask {
Subroutine _run_subtask: not called CC=4 SCAR=30.0
83 0 my ( $self, $task_name, %extra_params ) = @_;
84 0 my $subtask = OpenInteract2::Manage->new( $task_name, {
85 package_dir => $self->param( 'package_dir' ),
86 website_dir => $self->param( 'website_dir' ),
87 %extra_params
88 });
89 0 eval { $subtask->execute() };
90 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
91 0 $self->_fail( $task_name, "Caught error: $@" );
92 0 return 0;
93 }
94 0 my $is_ok = 1;
95 0 foreach my $status ( $subtask->get_status ) {
96 0 ▶ if ( $status->{is_ok} eq 'no' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status->{"is_ok"} eq "no") 0 0 0
97 0 $self->_fail( $task_name, $status->{message} );
98 0 $is_ok = 0;
99 }
100 }
101 0 return ( $is_ok, $subtask );
102 }
103  
104 87 OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ );
105  
106 87 1;
107  
108 __END__
« OpenInteract2/Setup/ReadActionTable.pm ↑ Summary OpenInteract2/Manage/Website/RemovePackage.pm »