line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::MVP::Reader::Hash; |
2
|
|
|
|
|
|
|
# ABSTRACT: a reader that tries to cope with a plain old hashref |
3
|
|
|
|
|
|
|
$Config::MVP::Reader::Hash::VERSION = '2.200012'; |
4
|
2
|
|
|
2
|
|
8343
|
use Moose; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
16
|
|
5
|
|
|
|
|
|
|
extends 'Config::MVP::Reader'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
8
|
|
|
|
|
|
|
#pod |
9
|
|
|
|
|
|
|
#pod my $sequence = Config::MVP::Reader::Hash->new->read_config( \%config ); |
10
|
|
|
|
|
|
|
#pod |
11
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
12
|
|
|
|
|
|
|
#pod |
13
|
|
|
|
|
|
|
#pod In some ways, this is the L<Config::MVP::Reader> of last resort. Given a |
14
|
|
|
|
|
|
|
#pod hashref, it attempts to interpret it as a Config::MVP::Sequence. Because |
15
|
|
|
|
|
|
|
#pod hashes are generally unordered, order can't be relied upon unless the hash tied |
16
|
|
|
|
|
|
|
#pod to have order (presumably with L<Tie::IxHash>). The hash keys are assumed to |
17
|
|
|
|
|
|
|
#pod be section names and will be used as the section package moniker unless a |
18
|
|
|
|
|
|
|
#pod L<__package> entry is found. |
19
|
|
|
|
|
|
|
#pod |
20
|
|
|
|
|
|
|
#pod =cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub read_into_assembler { |
23
|
3
|
|
|
3
|
1
|
8
|
my ($self, $location, $assembler) = @_; |
24
|
|
|
|
|
|
|
|
25
|
3
|
50
|
|
|
|
11
|
confess "no hash given to $self" unless my $hash = $location; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
10
|
for my $name (keys %$hash) { |
28
|
6
|
|
|
|
|
27
|
my $payload = { %{ $hash->{ $name } } }; |
|
6
|
|
|
|
|
25
|
|
29
|
6
|
|
66
|
|
|
28
|
my $package = delete($payload->{__package}) || $name; |
30
|
|
|
|
|
|
|
|
31
|
6
|
|
|
|
|
29
|
$assembler->begin_section($package, $name); |
32
|
|
|
|
|
|
|
|
33
|
6
|
|
|
|
|
130
|
for my $key (%$payload) { |
34
|
16
|
|
|
|
|
31
|
my $val = $payload->{ $key }; |
35
|
16
|
100
|
|
|
|
42
|
my @values = ref $val ? @$val : $val; |
36
|
16
|
|
|
|
|
51
|
$assembler->add_value($key => $_) for @values; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
6
|
|
|
|
|
28
|
$assembler->end_section; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
451
|
return $assembler->sequence; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
2
|
|
14385
|
no Moose; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
13
|
|
46
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=encoding UTF-8 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Config::MVP::Reader::Hash - a reader that tries to cope with a plain old hashref |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 VERSION |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
version 2.200012 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 SYNOPSIS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $sequence = Config::MVP::Reader::Hash->new->read_config( \%config ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
In some ways, this is the L<Config::MVP::Reader> of last resort. Given a |
70
|
|
|
|
|
|
|
hashref, it attempts to interpret it as a Config::MVP::Sequence. Because |
71
|
|
|
|
|
|
|
hashes are generally unordered, order can't be relied upon unless the hash tied |
72
|
|
|
|
|
|
|
to have order (presumably with L<Tie::IxHash>). The hash keys are assumed to |
73
|
|
|
|
|
|
|
be section names and will be used as the section package moniker unless a |
74
|
|
|
|
|
|
|
L<__package> entry is found. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHOR |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Ricardo Signes <rjbs@cpan.org> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Ricardo Signes. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
85
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |