line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CIAO::Lib::Param; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: An interface to the CIAO parameter library. |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
509377
|
use 5.012; |
|
2
|
|
|
|
|
23
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
38
|
|
8
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
88
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
12
|
use parent 'Exporter'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
10
|
|
13
|
|
|
|
|
|
|
our @CARP_NOT = qw/ CIAO::Lib::Param::Croak /; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _croak { |
16
|
0
|
|
|
0
|
|
0
|
require Carp; |
17
|
0
|
|
|
|
|
0
|
goto \&Carp::croak; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
21
|
|
|
|
|
|
|
'all' => [ qw( |
22
|
|
|
|
|
|
|
pget |
23
|
|
|
|
|
|
|
pquery |
24
|
|
|
|
|
|
|
pset |
25
|
|
|
|
|
|
|
pfind |
26
|
|
|
|
|
|
|
) ] ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
require XSLoader; |
33
|
|
|
|
|
|
|
XSLoader::load( 'CIAO::Lib::Param', $VERSION ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
## no critic (Modules::ProhibitMultiplePackages) |
36
|
|
|
|
|
|
|
# very simple exception class. don't use Exception::Class to avoid |
37
|
|
|
|
|
|
|
# too many dependencies for users. |
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
package CIAO::Lib::Param::Error; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
use overload |
42
|
|
|
|
|
|
|
'""' => \&error, |
43
|
5
|
|
|
5
|
|
9265
|
bool => sub { 1 }, |
44
|
0
|
|
|
0
|
|
0
|
eq => sub { die }, |
45
|
0
|
|
|
0
|
|
0
|
'.' => sub { $_[0]->errstr . $_[1] }, |
46
|
2
|
|
|
2
|
|
567
|
fallback => !!0; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
0
|
|
0
|
sub new { my $class = shift; bless {@_}, $class; } |
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
458
|
sub error { $_[0]->{error} } |
51
|
0
|
|
|
0
|
|
0
|
sub errno { $_[0]->{errno} } |
52
|
0
|
|
|
0
|
|
0
|
sub errstr { $_[0]->{errstr} } |
53
|
0
|
|
|
0
|
|
0
|
sub errmsg { $_[0]->{errmsg} } |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# simple wrapper around open to get croakability. note |
59
|
|
|
|
|
|
|
# that the object is blessed into CIAO::Lib::ParamPtr |
60
|
|
|
|
|
|
|
# by open. |
61
|
|
|
|
|
|
|
sub new { |
62
|
|
|
|
|
|
|
#my $class = |
63
|
14
|
|
|
14
|
1
|
26482
|
shift; |
64
|
|
|
|
|
|
|
|
65
|
14
|
|
|
|
|
20
|
my $self; |
66
|
14
|
|
|
|
|
24
|
my $file = shift; |
67
|
14
|
|
100
|
|
|
60
|
my $mode = shift || 'r'; |
68
|
|
|
|
|
|
|
|
69
|
14
|
|
|
|
|
30
|
my @arglist = @_; |
70
|
|
|
|
|
|
|
|
71
|
14
|
|
|
|
|
29
|
my $filename; |
72
|
|
|
|
|
|
|
|
73
|
14
|
100
|
|
|
|
38
|
if ( 'ARRAY' eq ref $file ) { |
74
|
2
|
|
|
|
|
5
|
$filename = $file->[0]; |
75
|
2
|
|
|
|
|
5
|
unshift @arglist, $file->[1]; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
else { |
79
|
12
|
|
|
|
|
27
|
unshift @arglist, $file; |
80
|
12
|
|
|
|
|
23
|
$filename = undef; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
14
|
|
|
1
|
|
33881
|
$self = CIAO::Lib::Param::open( $filename, $mode, @arglist ); |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
228
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
13
|
|
|
|
|
90
|
$self; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _pread { |
90
|
5
|
|
|
5
|
|
10
|
my $pfile = shift; |
91
|
5
|
|
|
|
|
12
|
my $mode = shift; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
5
|
100
|
|
|
|
17
|
my $argv = 'ARRAY' eq ref $_[0] ? shift : undef; |
95
|
5
|
|
|
|
|
8
|
my $wantarray = wantarray(); ## no critic (Community::Wantarray) |
96
|
|
|
|
|
|
|
|
97
|
5
|
100
|
|
|
|
23
|
my $pf = CIAO::Lib::Param->new( $pfile, $mode, defined $argv ? @$argv : () ); |
98
|
|
|
|
|
|
|
|
99
|
5
|
100
|
|
|
|
23
|
if ( @_ ) { |
100
|
4
|
|
|
|
|
10
|
my @bogus = grep { !$pf->access( $_ ) } @_; |
|
5
|
|
|
|
|
43
|
|
101
|
4
|
50
|
|
|
|
12
|
_croak( 'unknown parameters: ', join( ', ', @bogus ), "\n" ) |
102
|
|
|
|
|
|
|
if @bogus; |
103
|
4
|
100
|
|
|
|
144
|
return $wantarray ? map { $pf->get( $_ ) } @_ : $pf->get( $_[0] ); |
|
2
|
|
|
|
|
61
|
|
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
else { |
107
|
1
|
|
|
|
|
14
|
my $pm = $pf->match( q{*} ); |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
2
|
my @params; |
110
|
1
|
|
|
|
|
35
|
push @params, $_ while $_ = $pm->next; |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
3
|
return map { ( $_ => $pf->get( $_ ) ) } @params; |
|
18
|
|
|
|
|
192
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
die( "impossible!\n" ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# class get method to perform a one shot read of parameters |
119
|
|
|
|
|
|
|
# never query |
120
|
|
|
|
|
|
|
sub pget { |
121
|
5
|
|
|
5
|
1
|
19145
|
my $pfile = shift; |
122
|
|
|
|
|
|
|
|
123
|
5
|
|
|
|
|
17
|
unshift @_, $pfile, 'rH'; |
124
|
|
|
|
|
|
|
# act like we were never here |
125
|
5
|
|
|
|
|
21
|
goto &_pread; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# class get method to perform a one shot read of parameters |
129
|
|
|
|
|
|
|
sub pquery { |
130
|
0
|
|
|
0
|
1
|
0
|
my $pfile = shift; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
0
|
unshift @_, $pfile, 'r'; |
133
|
|
|
|
|
|
|
# act like we were never here |
134
|
0
|
|
|
|
|
0
|
goto &_pread; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub pset { |
138
|
2
|
|
|
2
|
1
|
3946
|
my ( $pfile, %params ) = @_; |
139
|
|
|
|
|
|
|
|
140
|
2
|
50
|
|
|
|
8
|
return unless keys %params; |
141
|
|
|
|
|
|
|
|
142
|
2
|
|
|
|
|
7
|
my $pf = CIAO::Lib::Param->new( $pfile, 'w' ); |
143
|
|
|
|
|
|
|
|
144
|
2
|
|
|
|
|
415
|
$pf->set( $_, $params{$_} ) for keys %params; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# |
150
|
|
|
|
|
|
|
# This file is part of CIAO-Lib-Param |
151
|
|
|
|
|
|
|
# |
152
|
|
|
|
|
|
|
# This software is Copyright (c) 2005 by Smithsonian Astrophysical Observatory. |
153
|
|
|
|
|
|
|
# |
154
|
|
|
|
|
|
|
# This is free software, licensed under: |
155
|
|
|
|
|
|
|
# |
156
|
|
|
|
|
|
|
# The GNU General Public License, Version 3, June 2007 |
157
|
|
|
|
|
|
|
# |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__END__ |