File Coverage

blib/lib/Config/Param/FileWorker.pm
Criterion Covered Total %
statement 54 54 100.0
branch 4 8 50.0
condition 1 3 33.3
subroutine 10 10 100.0
pod 7 7 100.0
total 76 82 92.6


line stmt bran cond sub pod time code
1             package Config::Param::FileWorker;
2              
3 2     2   113031 use Config::Param;
  2         64  
  2         126  
4 2     2   1225 use IO::File;
  2         17900  
  2         276  
5 2     2   481 use Storable qw(dclone);
  2         3144  
  2         1232  
6              
7             our $VERSION = '4.000006'; # updated by release script
8             $VERSION = eval $VERSION;
9              
10             sub new
11             {
12 1     1 1 213588 my $class = shift;
13 1         3 my $self = {};
14 1         4 bless $self, $class;
15 1         9 $self->{config} = shift;
16 1         5 $self->{config}{nofinals} = 1;
17 1         17 $self->{pardef} = shift;
18 1         13 $self->{pars} = Config::Param->new($self->{config},$self->{pardef});
19 1         70 $self->{defpars} = dclone($self->{pars}{param});
20 1         6 return $self;
21             }
22              
23             sub init_with_args
24             {
25 1     1 1 9 my $self = shift;
26 1         3 my $args = shift;
27 1 50       5 $args = \@ARGV unless defined $args;
28 1         7 $self->{pars}->parse_args($args);
29 1         6 $self->{pars}->use_config_files();
30 1         6 $self->{pars}->apply_args();
31 1         2 my $good = (not @{$self->{pars}{errors}});
  1         3  
32 1         4 $self->{pars}{errors} = [];
33 1         3 return $good;
34             }
35              
36             sub store_defaults
37             {
38 1     1 1 8 my $self = shift;
39 1         56 $self->{defpars} = dclone($self->{pars}{param});
40             }
41              
42             sub load_defaults
43             {
44 1     1 1 1465 my $self = shift;
45 1         61 $self->{pars}{param} = dclone($self->{defpars});
46             }
47              
48             sub param
49             {
50 7     7 1 1798 my $self = shift;
51             # Yes, it's a direct reference.
52 7         416 return $self->{pars}{param};
53             }
54              
55             sub load_file
56             {
57 1     1 1 7 my $self = shift;
58 1         2 my $file = shift;
59 1         7 $self->{pars}->parse_file($file);
60 1         2 my $good = (not @{$self->{pars}{errors}});
  1         4  
61 1         3 $self->{pars}{errors} = [];
62 1         5 return $good;
63             }
64              
65             sub store_file
66             {
67 1     1 1 1409 my $self = shift;
68 1         3 my $file = shift;
69 1 50 33     9 $file = undef if defined $file and $file eq '';
70 1         4 my $fh = \*STDOUT;
71 1 50       4 if(defined $file)
72             {
73 1         10 $fh = IO::File->new();
74 1 50       59 $fh->open($file, '>') or return 0;
75             }
76 1         322 $self->{pars}->print_file($fh);
77 1         15 $fh->close();
78 1         78 my $good = (not @{$self->{pars}{errors}});
  1         6  
79 1         4 $self->{pars}{errors} = [];
80 1         7 return $good;
81             }
82              
83             1;
84              
85             __END__