line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::YAML::Tiny; |
2
|
7
|
|
|
7
|
|
213086
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
486
|
|
3
|
7
|
|
|
7
|
|
39
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
294
|
|
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
7599
|
use YAML::Tiny qw(Load Dump); |
|
7
|
|
|
|
|
50816
|
|
|
7
|
|
|
|
|
844
|
|
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
77
|
use vars qw( $AUTOLOAD ); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
1828
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.42.0'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
9
|
|
|
9
|
1
|
2718
|
my $class = shift; |
13
|
9
|
|
|
|
|
19
|
my %priv = (); |
14
|
9
|
|
|
|
|
18
|
my %args = (); |
15
|
|
|
|
|
|
|
|
16
|
9
|
50
|
|
|
|
35
|
die("Can't create Config::YAML object with no config file.\n") |
17
|
|
|
|
|
|
|
if ( $_[0] ne "config" ); |
18
|
9
|
|
|
|
|
12
|
shift; |
19
|
9
|
|
|
|
|
27
|
$priv{config} = shift; |
20
|
|
|
|
|
|
|
|
21
|
9
|
100
|
66
|
|
|
51
|
if ( @_ && ( $_[0] eq "output" ) ) { shift; $priv{output} = shift; } |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
9
|
|
22
|
9
|
50
|
66
|
|
|
40
|
if ( @_ && ( $_[0] eq "strict" ) ) { shift; $priv{strict} = shift; } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
23
|
|
|
|
|
|
|
|
24
|
9
|
|
66
|
|
|
118
|
my $self = bless { |
|
|
|
50
|
|
|
|
|
25
|
|
|
|
|
|
|
_infile => $priv{config}, |
26
|
|
|
|
|
|
|
_outfile => $priv{output} || $priv{config}, |
27
|
|
|
|
|
|
|
_strict => $priv{strict} || 0, |
28
|
|
|
|
|
|
|
}, $class; |
29
|
|
|
|
|
|
|
|
30
|
9
|
|
|
|
|
21
|
%args = @_; |
31
|
9
|
|
|
|
|
23
|
@{$self}{ keys %args } = values %args; |
|
9
|
|
|
|
|
43
|
|
32
|
|
|
|
|
|
|
|
33
|
9
|
|
|
|
|
37
|
$self->read; |
34
|
9
|
|
|
|
|
61
|
return $self; |
35
|
|
|
|
|
|
|
} ## end sub new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub Config::YAML::Tiny::AUTOLOAD { |
38
|
7
|
|
|
7
|
|
41
|
no strict 'refs'; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
11769
|
|
39
|
7
|
|
|
7
|
|
1670
|
my ( $self, $newval ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
7
|
100
|
|
|
|
31
|
if ( $AUTOLOAD =~ /.*::get_(\w+)/ ) { |
42
|
4
|
|
|
|
|
7
|
my $attr = $1; |
43
|
4
|
100
|
|
|
|
14
|
return undef if ( !defined $self->{$attr} ); |
44
|
3
|
|
|
1
|
|
10
|
*{$AUTOLOAD} = sub { return $_[0]->{$attr} }; |
|
3
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
4
|
|
45
|
3
|
|
|
|
|
21
|
return $self->{$attr}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
3
|
50
|
|
|
|
16
|
if ( $AUTOLOAD =~ /.*::set_(\w+)/ ) { |
49
|
3
|
|
|
|
|
5
|
my $attr = $1; |
50
|
3
|
|
|
0
|
|
10
|
*{$AUTOLOAD} = sub { $_[0]->{$attr} = $_[1]; return }; |
|
3
|
|
|
|
|
10
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
51
|
3
|
|
|
|
|
26
|
$self->{$attr} = $newval; |
52
|
3
|
|
|
|
|
6
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub fold { |
57
|
1
|
|
|
1
|
1
|
6
|
my ( $self, $data ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# add check for HASHREF when strict mode is implemented |
60
|
1
|
|
|
|
|
2
|
@{$self}{ keys %{$data} } = values %{$data}; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub read { |
64
|
10
|
|
|
10
|
1
|
348
|
my ( $self, $file ) = @_; |
65
|
10
|
100
|
|
|
|
30
|
$self->{_infile} = $file if $file; |
66
|
|
|
|
|
|
|
|
67
|
10
|
|
|
|
|
16
|
my $yaml = ''; |
68
|
10
|
|
|
|
|
13
|
my $line; |
69
|
|
|
|
|
|
|
|
70
|
10
|
50
|
|
|
|
364
|
open( FH, '<', $self->{_infile} ) |
71
|
|
|
|
|
|
|
or die "Can't open $self->{_infile}; $!\n"; |
72
|
10
|
|
|
|
|
126
|
while ( $line = ) { |
73
|
190
|
100
|
|
|
|
421
|
next if ( $line =~ /^\-{3,}/ ); |
74
|
181
|
50
|
|
|
|
297
|
next if ( $line =~ /^#/ ); |
75
|
181
|
50
|
|
|
|
324
|
next if ( $line =~ /^$/ ); |
76
|
181
|
|
|
|
|
397
|
$yaml .= $line; |
77
|
|
|
|
|
|
|
} |
78
|
10
|
|
|
|
|
95
|
close(FH); |
79
|
10
|
|
|
|
|
46
|
my $tmpyaml = Load($yaml); |
80
|
10
|
|
|
|
|
9185
|
@{$self}{ keys %{$tmpyaml} } = values %{$tmpyaml}; # woo, hash slice |
|
10
|
|
|
|
|
90
|
|
|
10
|
|
|
|
|
39
|
|
|
10
|
|
|
|
|
32
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub write { |
84
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
85
|
1
|
|
|
|
|
2
|
my %tmpyaml; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# strip out internal state parameters |
88
|
1
|
|
|
|
|
2
|
while ( my ( $k, $v ) = each %{$self} ) { |
|
15
|
|
|
|
|
46
|
|
89
|
14
|
100
|
|
|
|
48
|
$tmpyaml{$k} = $v unless ( $k =~ /^_/ ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# write data out to file |
93
|
1
|
50
|
|
|
|
156
|
open( FH, '>', $self->{_outfile} ) |
94
|
|
|
|
|
|
|
or die "Can't open $self->{_outfile}: $!\n"; |
95
|
1
|
|
|
|
|
6
|
print FH Dump( \%tmpyaml ); |
96
|
1
|
|
|
|
|
899
|
close(FH); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub get { |
100
|
0
|
|
|
0
|
1
|
|
my ( $self, $arg ) = @_; |
101
|
0
|
|
|
|
|
|
return $self->{$arg}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub set { |
105
|
0
|
|
|
0
|
1
|
|
my ( $self, $key, $val ) = @_; |
106
|
0
|
|
|
|
|
|
$self->{$key} = $val; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; # End of Config::YAML |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |