line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Verby::Config::Data; |
4
|
6
|
|
|
6
|
|
253750
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use List::MoreUtils qw/uniq/; |
9
|
|
|
|
|
|
|
use Carp qw/croak/; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has data => ( |
12
|
|
|
|
|
|
|
isa => "HashRef", |
13
|
|
|
|
|
|
|
is => "rw", |
14
|
|
|
|
|
|
|
default => sub { return {} }, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has parents => ( |
18
|
|
|
|
|
|
|
isa => "ArrayRef", |
19
|
|
|
|
|
|
|
is => "ro", |
20
|
|
|
|
|
|
|
auto_deref => 1, |
21
|
|
|
|
|
|
|
required => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
around new => sub { |
25
|
|
|
|
|
|
|
my $next = shift; |
26
|
|
|
|
|
|
|
my ( $class, @parents ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$class->$next( parents => [ uniq @parents ] ); |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub DEMOLISH { |
32
|
|
|
|
|
|
|
my $self = shift; |
33
|
|
|
|
|
|
|
untie %{ $self->{data} } if tied $self->{data}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub AUTOLOAD { |
37
|
|
|
|
|
|
|
(our $AUTOLOAD) =~ /::([^:]+)$/; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $field = $1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $sub = sub { |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
$self->set($field, @_) if @_; |
44
|
|
|
|
|
|
|
$self->get($field); |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
no strict; |
49
|
|
|
|
|
|
|
*{ $field } = $sub; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
goto &$sub; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub set { |
56
|
|
|
|
|
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
croak "$self is not mutable"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub get { |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
my $key = shift; |
63
|
|
|
|
|
|
|
($self->search($key) || return)->extract($key); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub extract { |
67
|
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
my $key = shift; |
69
|
|
|
|
|
|
|
$self->data->{$key}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub exists { |
73
|
|
|
|
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
my $key = shift; |
75
|
|
|
|
|
|
|
$self->data->{$key} || exists $self->data->{$key}; # XXX workaround for Tie::Memoize |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub search { |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
my $key = shift; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
if ( $self->exists($key) ) { |
83
|
|
|
|
|
|
|
return $self; |
84
|
|
|
|
|
|
|
} else { |
85
|
|
|
|
|
|
|
my @matches = uniq map { $_->search($key) } $self->parents; |
86
|
|
|
|
|
|
|
if ( @matches == 1 ) { |
87
|
|
|
|
|
|
|
return $matches[0]; |
88
|
|
|
|
|
|
|
} else { |
89
|
|
|
|
|
|
|
Log::Dispatch::Config->instance->warn("Parents config sources conflict over $key: @matches") if @matches; |
90
|
|
|
|
|
|
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub derive { |
96
|
|
|
|
|
|
|
my ( $self, $class ) = @_; |
97
|
|
|
|
|
|
|
$class ||= ref $self; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$class->new($self); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__PACKAGE__ |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Verby::Config::Data - |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SYNOPSIS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
use Verby::Config::Data; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 DESCRIPTION |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 METHODS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=over 4 |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item B<new> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item B<set> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item B<get> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item B<extract> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item B<exists> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item B<search> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item B<derive> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item B<data> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item B<parents> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 BUGS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
None that we are aware of. Of course, if you find a bug, let us know, and we will be sure to fix it. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 CODE COVERAGE |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
We use B<Devel::Cover> to test the code coverage of the tests, please refer to COVERAGE section of the L<Verby> module for more information. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 SEE ALSO |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Yuval Kogman, E<lt>nothingmuch@woobling.orgE<gt> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Copyright 2005-2008 by Infinity Interactive, Inc. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L<http://www.iinteractive.com> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
163
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |