CrlPublish/Target.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 98 CC 8 SCAR 19.4
CC
8
Cov
0%
new
12.0
AUTOLOAD
12.0
find
6.0
CRAP 6.9
1 package EJBCA::CrlPublish::Target;
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::Target
31  
32 =head1 SYNOPSIS
33  
34 A flexible attribute container class, used for collecting the right
35 configuration values for a given certificate revocation list, and given to
36 the EJBCA::CrlPublish::Method class as its sole argument.
37  
38 =cut
39  
40  
41 ###############################################################################
42 # Library dependencies.
43  
44 use Carp;
45  
46 our $VERSION = '0.60';
47  
48  
49 ###############################################################################
50  
51 =head1 CONSTRUCTOR
52  
53 =head2 EJBCA::CrlPublish::Target->new( %attributes );
54  
55 Creates a new empty object. Any arguments supplied as a hash will be applied
56 to the object before returning. These arguments will not behave any differently
57 than those supplied as attribute method calls, see below.
58  
59 Note: you probably want the find constructor, see below.
60  
61 Returns a blessed EJBCA::CrlPublish::Target reference.
62  
63 =cut
64  
65 sub new {
66 my ( $class, %args ) = @_;
67  
68 $class = ref( $class ) if ref( $class );
69  
70 unless ( $class->isa( __PACKAGE__ ) ) {
71 confess "Asinine construction of $class";
72 }
73  
74 bless my $self = {}, $class;
75  
76 foreach my $arg ( keys %args ) {
77 $self->$arg( $args{$arg} );
78 }
79  
80 return $self;
81 }
82  
83  
84 ###############################################################################
85 # Copy Constructor
86  
87 sub copyObject {
88 my $self = shift;
89  
90 my $obj = bless { %$self }, ref( $self );
91  
92 return $obj;
93 }
94  
95  
96 ###############################################################################
97  
98 =head1 SEARCH CONSTRUCTOR
99  
100 =head2 EJBCA::CrlPublish::Target->find( $crlInfo );
101  
102 Given an EJBCA::CrlPublish::CrlInfo argument, returns a list of Target objects
103 representing each publishing target, with each containing all known relevant
104 configuration attributes.
105  
106 Returns a list of blessed, populated EJBCA::CrlPublish::Target references.
107  
108 =cut
109  
110 sub find {
111 my ( $class, $crlInfo ) = @_;
112  
113 my $issuerDn = $crlInfo->issuerDn;
114  
115 my $targ = $class->new(
116 crlInfo => $crlInfo,
117 issuerDn => $issuerDn );
118
119 # apply fixed defaults
120 $targ->publishMethod( 'scp' );
121  
122 # apply crlInfo details
123 if ( $crlInfo->issuingUrl ) {
124 $targ->issuingUrl( $crlInfo->issuingUrl );
125 $targ->remoteHost( $crlInfo->issuingHost );
126 $targ->remotePath( $crlInfo->issuingPath );
127 $targ->remoteFile( $crlInfo->issuingFile );
128 }
129  
130 # apply defaults section
131 EJBCA::CrlPublish::Config->applySection( 'defaults', $targ );
132  
133 # apply issuerDn specific section
134 EJBCA::CrlPublish::Config->applySection( $issuerDn, $targ );
135  
136 # apply target host specific section
137 EJBCA::CrlPublish::Config->applySection( $targ->remoteHost, $targ );
138  
139 my @targets;
140 foreach my $remoteHost ( split /\s*,\s*/, $targ->remoteHost ) {
141 my $target = $targ->copyObject;
142 $target->remoteHost( $remoteHost );
143 push @targets, $target;
144 }
145  
146 return @targets;
147 }
148  
149  
150 ###############################################################################
151  
152 =head1 FIXED ATTRIBUTES
153  
154 =head2 $self->crlFile
155  
156 An alias for $self->crlInfo->crlFile
157  
158 =cut
159  
160 sub crlFile {
161 my $self = shift;
162 return undef unless $self->crlInfo;
163 return $self->crlInfo->crlFile;
164 }
165  
166  
167 ###############################################################################
168  
169 =head1 OTHER ATTRIBUTES
170  
171 =head2 $self->attrib( "attributeName" );
172  
173 =head2 $self->attrib( "attributeName", "value" );
174  
175 A generic attribute accessor/mutator.
176  
177 This should not be called directly; it is used by AUTOLOAD to create closures.
178  
179 Just call $self->attributeName and $self->attributeName( "value" ) and this
180 module will take care of the rest.
181  
182 =cut
183  
184 sub attrib {
185 my ( $self, $name, $value ) = @_;
186  
187 if ( defined $value ) {
188 $self->{$name} = $value;
189 }
190  
191 return $self->{$name};
192 }
193  
194  
195 ###############################################################################
196 # Automagic attribute mutator method generator
197  
198 our $AUTOLOAD;
199  
200 sub AUTOLOAD {
201 my $this = shift;
202 my $name = $AUTOLOAD;
203  
204 # only function for instance calls
205 unless ( ref( $this ) and $this->isa( __PACKAGE__ ) ) {
206 confess "Method $name not found";
207 }
208  
209 # strip off the "fully qualified" part of the method name
210 $name =~ s/.*://;
211  
212 # bail immediately if it's looking for a destructor
213 return if $name eq 'DESTROY';
214  
215 my $func = sub {
216 my $self = shift;
217 return $self->attrib( $name, shift );
218 };
219  
220 {
221 no strict 'refs';
222 *$AUTOLOAD = $func;
223 }
224  
225 return &$func( $this, @_ );
226 }
227  
228  
229 ###############################################################################
230  
231 =head1 AUTHOR
232  
233 Kevin Cody-Little <kcody@cpan.org>
234  
235 =cut
236  
237  
238 ###############################################################################
239 ####################################### EOF ###################################
240 ###############################################################################
241 1;