CrlPublish/Method.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 98 CC 11 SCAR 31.7
CC
11
Cov
0%
execute
56.0
checkFileType
20.0
argMustExist
6.0
CRAP 23.8
1 package EJBCA::CrlPublish::Method;
2 use warnings;
3 use strict;
4 #
5 # crlpublish
6 #
7 # Copyright (C) 2014, Kevin Cody-Little <kcody@cpan.org>
8 #
9 # Portions derived from crlpublisher.sh, original copyright follows:
10 #
11 # Copyright (C) 2011, Branko Majic <branko@majic.rs>
12 #
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #
26 ###############################################################################
27  
28 =head1 NAME
29  
30 EJBCA::CrlPublish::Method
31  
32 =head1 SYNOPSIS
33  
34 Base class for flexible publishing methods.
35  
36 This is invoked by EJBCA::CrlPublish to actually transfer a CRL.
37  
38 =cut
39  
40  
41 ###############################################################################
42 # Library dependencies
43  
44 use Carp;
45 use EJBCA::CrlPublish::Logging;
46  
47 our $VERSION = '0.60';
48  
49  
50 ###############################################################################
51  
52 =head1 INVOCATION
53  
54 =head2 EJBCA::CrlPublish::Method->execute( $target )
55  
56 Argument must be a single EJBCA::CrlPublish::Target object.
57  
58 This is the only function that should be called directly, except by subclasses.
59  
60 =cut
61  
62 sub execute {
63 my ( $class, $target ) = @_;
64  
65 $class = ref( $class ) if ref( $class );
66  
67 unless ( $class->isa( __PACKAGE__ ) ) {
68 confess "Asinine construction of $class";
69 }
70  
71 unless ( $target->isa( 'EJBCA::CrlPublish::Target' ) ) {
72 confess 'Expecting Target object, got ' . ref( $target );
73 }
74  
75 my $meth = $target->publishMethod;
76  
77 unless ( $meth ) {
78 msgError "Unable to determine publishing method.";
79 return undef;
80 }
81  
82 my $oclass = __PACKAGE__ . '::' . $meth;
83 my $classp = __PACKAGE__ . '::' . $meth . '.pm';
84 $classp =~ s/::/\//g;
85  
86 unless ( require $classp ) {
87 msgError "Publishing method $meth not found.";
88 return undef;
89 }
90  
91 bless my $self = {}, $oclass;
92  
93 $self->{target} = $target;
94  
95 unless ( $self->validate ) {
96 msgError "Publishing pre-validation failed.";
97 return undef;
98 }
99  
100 return $self->publish;
101 }
102  
103  
104 ###############################################################################
105  
106 =head1 HELPER METHODS
107  
108 These are used by subclasses that implement specific publishing methods.
109  
110 =head2 $self->target
111  
112 Returns the EJBCA::CrlPublish::Target object that was passed to execute, above.
113  
114 =cut
115  
116 sub target {
117 return (shift)->{target};
118 }
119  
120 =head2 $self->argMustExist( @argNames )
121  
122 Croaks if the target object is missing any of the supplied attribute names.
123  
124 =cut
125  
126 sub argMustExist {
127 my $self = shift;
128  
129 while ( my $arg = shift ) {
130 next if $self->target->$arg;
131 msgError "Required attribute '$arg' not present.";
132 return 0;
133 }
134  
135 return 1;
136 }
137  
138 =head2 $self->checkFileType( $name, $path )
139  
140 First argument is used to prefix error messages, second is a path to a file.
141  
142 Croaks if the file isn't present, plain, and readable.
143  
144 =cut
145  
146 sub checkFileType {
147 my ( $self, $name, $path ) = @_;
148  
149 unless ( -e $path ) {
150 msgError "$name file '$path' not found.";
151 return 0;
152 }
153  
154 unless ( -f $path ) {
155 msgError "$name file '$path' not a file.";
156 return 0;
157 }
158  
159 unless ( -r $path ) {
160 msgError "$name file '$path' not readable.";
161 return 0;
162 }
163  
164 return 1;
165 }
166  
167  
168 ###############################################################################
169  
170 =head1 ABSTRACT METHODS
171  
172 Subclasses implementing specific publishing methods must provide these.
173  
174 =head2 $self->validate
175  
176 Croaks if it doesn't like something about the supplied Target object.
177  
178 =cut
179  
180 sub validate {
181 my $self = shift;
182  
183 confess "Abstract method invocation";
184  
185 }
186  
187 =head2 $self->publish
188  
189 Accomplish the publish. Called only if $self->validate succeeds.
190  
191 =cut
192  
193 sub publish {
194 my $self = shift;
195  
196 confess "Abstract method invocation";
197  
198 }
199  
200  
201 ###############################################################################
202  
203 =head1 AUTHOR
204  
205 Kevin Cody-Little <kcody@cpan.org>
206  
207 =cut
208  
209  
210 ###############################################################################
211 ####################################### EOF ###################################
212 ###############################################################################
213 1;