| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::PerlShell::Config; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
######################################################## |
|
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
|
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
|
6
|
|
|
|
|
|
|
######################################################## |
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
117709
|
use strict; |
|
|
2
|
|
|
|
|
11
|
|
|
|
2
|
|
|
|
|
51
|
|
|
9
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
37
|
|
|
10
|
2
|
|
|
2
|
|
20
|
use Carp; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
110
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
12
|
use Exporter; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
1411
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'config_where' => [qw( config_where )], ); |
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{$EXPORT_TAGS{'config_where'}} ); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @ISA = qw( Exporter ); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
1
|
|
|
1
|
1
|
75
|
my $self = shift; |
|
21
|
1
|
|
33
|
|
|
7
|
my $class = ref($self) || $self; |
|
22
|
|
|
|
|
|
|
|
|
23
|
1
|
50
|
|
|
|
5
|
if ( ( @_ % 2 ) == 1 ) { |
|
24
|
0
|
|
|
|
|
0
|
croak("Insufficient number of args - @_"); |
|
25
|
|
|
|
|
|
|
} else { |
|
26
|
1
|
|
|
|
|
4
|
my %cfg = @_; |
|
27
|
1
|
|
|
|
|
3
|
return bless \%cfg, $class; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub config { |
|
32
|
11
|
|
|
11
|
1
|
1615
|
my $self = shift; |
|
33
|
11
|
|
|
|
|
20
|
my ( $key, $value ) = @_; |
|
34
|
|
|
|
|
|
|
|
|
35
|
11
|
|
|
|
|
16
|
my $retType = wantarray; |
|
36
|
11
|
100
|
|
|
|
20
|
if ( defined $key ) { |
|
37
|
10
|
100
|
|
|
|
20
|
if ( exists $self->{$key} ) { |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Set |
|
40
|
7
|
100
|
|
|
|
13
|
if ( defined $value ) { |
|
41
|
2
|
|
|
|
|
3
|
my $prev = $self->{$key}; |
|
42
|
2
|
50
|
|
|
|
5
|
if ( $value eq '' ) { |
|
43
|
0
|
|
|
|
|
0
|
undef $self->{$key}; |
|
44
|
|
|
|
|
|
|
} else { |
|
45
|
2
|
|
|
|
|
3
|
$self->{$key} = $value; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
2
|
50
|
|
|
|
10
|
return ( defined $prev ) ? $prev : undef; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Get |
|
50
|
|
|
|
|
|
|
} else { |
|
51
|
5
|
50
|
|
|
|
11
|
if ( !defined $retType ) { |
|
52
|
|
|
|
|
|
|
printf "%-15s => %s\n", $key, |
|
53
|
0
|
0
|
|
|
|
0
|
defined( $self->{$key} ) ? $self->{$key} : 'undef'; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
5
|
|
|
|
|
20
|
return $self->{$key}; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} else { |
|
58
|
3
|
50
|
|
|
|
7
|
if ( !defined $retType ) { |
|
59
|
0
|
|
|
|
|
0
|
carp("Key not valid - `$key'"); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
3
|
|
|
|
|
11
|
return undef; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Get all |
|
65
|
|
|
|
|
|
|
} else { |
|
66
|
1
|
50
|
|
|
|
6
|
if ( !defined($retType) ) { |
|
|
|
50
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
for ( sort( keys( %{$self} ) ) ) { |
|
|
0
|
|
|
|
|
0
|
|
|
68
|
|
|
|
|
|
|
printf "%-15s => %s\n", $_, |
|
69
|
0
|
0
|
|
|
|
0
|
defined( $self->{$_} ) ? $self->{$_} : 'undef'; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} elsif ($retType) { |
|
72
|
0
|
|
|
|
|
0
|
return %{$self}; |
|
|
0
|
|
|
|
|
0
|
|
|
73
|
|
|
|
|
|
|
} else { |
|
74
|
1
|
|
|
|
|
19
|
my %ret = %{$self}; |
|
|
1
|
|
|
|
|
9
|
|
|
75
|
1
|
|
|
|
|
5
|
return \%ret; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub add { |
|
81
|
5
|
|
|
5
|
1
|
557
|
my $self = shift; |
|
82
|
5
|
|
|
|
|
9
|
my ( $key, $value ) = @_; |
|
83
|
|
|
|
|
|
|
|
|
84
|
5
|
|
|
|
|
8
|
my $retType = wantarray; |
|
85
|
5
|
100
|
|
|
|
10
|
if ( defined $key ) { |
|
86
|
4
|
100
|
|
|
|
7
|
if ( !exists $self->{$key} ) { |
|
87
|
2
|
100
|
|
|
|
5
|
if ( defined $value ) { |
|
88
|
1
|
|
|
|
|
4
|
$self->{$key} = $value; |
|
89
|
|
|
|
|
|
|
} else { |
|
90
|
1
|
|
|
|
|
2
|
$self->{$key} = undef; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
2
|
|
|
|
|
8
|
return 1; |
|
93
|
|
|
|
|
|
|
} else { |
|
94
|
2
|
100
|
|
|
|
7
|
if ( !defined $retType ) { |
|
95
|
1
|
|
|
|
|
67
|
carp("Key exists"); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} else { |
|
99
|
1
|
|
|
|
|
70
|
carp("Key required"); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
3
|
|
|
|
|
70
|
return 0; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub delete { |
|
105
|
4
|
|
|
4
|
1
|
486
|
my $self = shift; |
|
106
|
4
|
|
|
|
|
7
|
my ($key) = @_; |
|
107
|
|
|
|
|
|
|
|
|
108
|
4
|
|
|
|
|
7
|
my $retType = wantarray; |
|
109
|
4
|
100
|
|
|
|
9
|
if ( defined $key ) { |
|
110
|
3
|
100
|
|
|
|
7
|
if ( exists $self->{$key} ) { |
|
111
|
1
|
|
|
|
|
2
|
delete $self->{$key}; |
|
112
|
1
|
|
|
|
|
9
|
return 1; |
|
113
|
|
|
|
|
|
|
} else { |
|
114
|
2
|
100
|
|
|
|
5
|
if ( !defined $retType ) { |
|
115
|
1
|
|
|
|
|
68
|
carp("Key doesn't exist"); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} else { |
|
119
|
1
|
|
|
|
|
70
|
carp("Key required"); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
3
|
|
|
|
|
60
|
return 0; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub exists { |
|
125
|
3
|
|
|
3
|
1
|
247
|
my $self = shift; |
|
126
|
3
|
|
|
|
|
6
|
my ($key) = @_; |
|
127
|
|
|
|
|
|
|
|
|
128
|
3
|
100
|
|
|
|
7
|
if ( defined $key ) { |
|
129
|
2
|
100
|
|
|
|
6
|
if ( exists $self->{$key} ) { |
|
130
|
1
|
|
|
|
|
5
|
return 1; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
} else { |
|
133
|
1
|
|
|
|
|
180
|
carp("Key required"); |
|
134
|
|
|
|
|
|
|
} |
|
135
|
2
|
|
|
|
|
45
|
return 0; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub config_where { |
|
139
|
0
|
|
|
0
|
1
|
|
my ( $config_file, $dir ) = @_; |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $home_dir = $ENV{HOME}; |
|
142
|
0
|
0
|
0
|
|
|
|
if ( ( $^O eq 'MSWin32' ) and !( defined $home_dir ) ) { |
|
143
|
0
|
|
|
|
|
|
$home_dir = $ENV{USERPROFILE}; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# 1 current working directory |
|
147
|
0
|
0
|
0
|
|
|
|
if ( -e $config_file ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
return $config_file |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# 2 user home directory |
|
151
|
|
|
|
|
|
|
} elsif ( -e $home_dir . "/" . $config_file ) { |
|
152
|
0
|
|
|
|
|
|
return $home_dir . "/" . $config_file; |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# 3 provided directory |
|
155
|
|
|
|
|
|
|
} elsif ( ( defined $dir ) and ( -e $dir . "/" . $config_file ) ) { |
|
156
|
0
|
|
|
|
|
|
return $dir . "/" . $config_file; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# not found - indicate so in config |
|
159
|
|
|
|
|
|
|
} else { |
|
160
|
0
|
|
|
|
|
|
return; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |