1 |
package WebPAC::Common; |
package WebPAC::Common; |
2 |
|
use Exporter 'import'; |
3 |
|
@EXPORT = qw/ |
4 |
|
force_array |
5 |
|
/; |
6 |
|
|
7 |
use warnings; |
use warnings; |
8 |
use strict; |
use strict; |
11 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
12 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
13 |
use File::Spec; |
use File::Spec; |
14 |
|
use Cwd qw/abs_path/; |
15 |
|
|
16 |
use base qw/Class::Accessor/; |
use base qw/Class::Accessor/; |
17 |
__PACKAGE__->mk_accessors( qw/log_debug no_log debug/ ); |
__PACKAGE__->mk_accessors( qw/log_debug no_log debug/ ); |
168 |
|
|
169 |
=cut |
=cut |
170 |
|
|
171 |
|
my $abs_path; |
172 |
|
|
173 |
sub var_path { |
sub var_path { |
174 |
my $self = shift; |
my $self = shift; |
175 |
|
|
176 |
return File::Spec->catfile('var', @_); |
if ( ! $abs_path ) { |
177 |
|
# $abs_path = abs_path( $0 ); |
178 |
|
# $abs_path =~ s!/WebPAC/Common\.pm!!; |
179 |
|
$abs_path = '/data/webpac2'; |
180 |
|
} |
181 |
|
|
182 |
|
return File::Spec->catfile($abs_path, 'var', @_); |
183 |
|
} |
184 |
|
|
185 |
|
=head1 EXPORTED NETHODS |
186 |
|
|
187 |
|
=head2 force_array |
188 |
|
|
189 |
|
my @array = force_array( $ref, sub { |
190 |
|
warn "reference is undefined!"; |
191 |
|
}); |
192 |
|
|
193 |
|
=cut |
194 |
|
|
195 |
|
sub force_array { |
196 |
|
my ( $what, $error ) = @_; |
197 |
|
my @result; |
198 |
|
if ( ref( $what ) eq 'ARRAY' ) { |
199 |
|
@result = @{ $what }; |
200 |
|
} elsif ( defined $what ) { |
201 |
|
@result = ( $what ); |
202 |
|
} else { |
203 |
|
$error->() if ref($error) eq 'CODE'; |
204 |
|
} |
205 |
|
return @result; |
206 |
} |
} |
207 |
|
|
208 |
|
|
267 |
my $conf = q( ); |
my $conf = q( ); |
268 |
if ($self->no_log) { |
if ($self->no_log) { |
269 |
warn "# $name disabled logging\n" if $self->log_debug; |
warn "# $name disabled logging\n" if $self->log_debug; |
270 |
|
$Log::Log4perl::Config::CONFIG_INTEGRITY_CHECK = 0; |
271 |
} elsif ($self->debug) { |
} elsif ($self->debug) { |
272 |
$conf = << '_log4perl_'; |
$conf = << '_log4perl_'; |
273 |
|
|