line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
4764
|
use 5.014; |
|
1
|
|
|
|
|
17
|
|
2
|
1
|
|
|
1
|
|
16
|
use strict; |
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
63
|
|
3
|
1
|
|
|
1
|
|
15
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
157
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Banal::Moosy::Mungers; # git description: a4d662b |
6
|
|
|
|
|
|
|
# vim: set ts=2 sts=2 sw=2 tw=115 et : |
7
|
|
|
|
|
|
|
# ABSTRACT: Provide several MUNGER functions that may be use in conjunction with C. |
8
|
|
|
|
|
|
|
# KEYWORDS: Munge Has has MungeHas MooseX::MungeHas Moose MooseX Moo MooX |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
11
|
|
|
|
|
|
|
# AUTHORITY |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
768
|
use Data::Printer; # DEBUG purposes. |
|
1
|
|
|
|
|
43705
|
|
|
1
|
|
|
|
|
7
|
|
14
|
1
|
|
|
1
|
|
759
|
use Banal::Util::Mini qw(peek tidy_arrayify); |
|
1
|
|
|
|
|
40074
|
|
|
1
|
|
|
|
|
11
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
1207
|
use namespace::autoclean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
7
|
use Exporter::Shiny qw( |
19
|
|
|
|
|
|
|
mhs_dict |
20
|
|
|
|
|
|
|
mhs_dictionary |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
mhs_fallbacks |
23
|
|
|
|
|
|
|
mhs_lazy_ro |
24
|
|
|
|
|
|
|
mhs_specs |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
std_haz_mungers |
27
|
1
|
|
|
1
|
|
67
|
); |
|
1
|
|
|
|
|
2
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
####################################### |
30
|
|
|
|
|
|
|
sub std_haz_mungers { |
31
|
|
|
|
|
|
|
####################################### |
32
|
|
|
|
|
|
|
our %mungers = ( |
33
|
0
|
|
|
0
|
|
|
haz => [ sub {; mhs_lazy_ro() } ], |
34
|
0
|
|
|
0
|
|
|
haz_bool => [ sub {; mhs_lazy_ro(isa=>'Bool') } ], |
35
|
0
|
|
|
0
|
|
|
haz_int => [ sub {; mhs_lazy_ro(isa=>'Int') } ], |
36
|
0
|
|
|
0
|
|
|
haz_str => [ sub {; mhs_lazy_ro(isa=>'Str') } ], |
37
|
0
|
|
|
0
|
|
|
haz_strs => [ sub {; mhs_lazy_ro(isa=>'ArrayRef[Str]', traits=>['Array'] ) } ], |
38
|
0
|
|
|
0
|
0
|
|
haz_hash => [ sub {; mhs_lazy_ro(isa=>'HashRef', traits=>['Hash'] ) } ], |
|
0
|
|
|
0
|
|
|
|
39
|
|
|
|
|
|
|
); |
40
|
0
|
|
|
|
|
|
%mungers; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
####################################### |
44
|
|
|
|
|
|
|
sub mhs_fallbacks { |
45
|
|
|
|
|
|
|
####################################### |
46
|
0
|
|
|
0
|
0
|
|
require Banal::Moosy::Mungers::DeviseFallbacks; |
47
|
0
|
|
|
|
|
|
goto &Banal::Moosy::Mungers::DeviseFallbacks::mhs_fallbacks; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
####################################### |
52
|
|
|
|
|
|
|
sub mhs_lazy_ro { |
53
|
|
|
|
|
|
|
####################################### |
54
|
0
|
|
|
0
|
0
|
|
mhs_specs( is => 'ro', init_arg => undef, lazy => 1, @_ ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
####################################### |
59
|
|
|
|
|
|
|
sub mhs_specs { # Define meta specs for attributes (is, isa, lazy, ...) |
60
|
|
|
|
|
|
|
####################################### |
61
|
|
|
|
|
|
|
# ATTENTION : Special calling convention and interface defined by MooseX::MungeHas. |
62
|
0
|
|
|
0
|
0
|
|
my $name = $_; # $_ contains the attribute NAME |
63
|
0
|
|
|
|
|
|
%_ = (@_, %_); # %_ contains the attribute SPECS, whereas @_ contains defaults (prefs) for those specs. |
64
|
0
|
0
|
|
|
|
|
wantarray ? (%_) : +{%_} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
####################################### |
68
|
0
|
|
|
0
|
0
|
|
sub mhs_dict { &mhs_dictionary } |
69
|
|
|
|
|
|
|
sub mhs_dictionary { |
70
|
|
|
|
|
|
|
# - Lookup meta specs for attributes from a given (src) dictonary; |
71
|
|
|
|
|
|
|
# * Parameters destined to this routine (dict, src/src_dict, dest/dest_dict) will be removed from the context. |
72
|
|
|
|
|
|
|
# * Remaining parameters will win over the values looked up from the src dictionnary. |
73
|
|
|
|
|
|
|
# * Current munge context (%_) wins over all of the above |
74
|
|
|
|
|
|
|
# - [OPTIONALLY] : merge the resulting specs onto a given (dest) dictionary, which may the same as (serc) |
75
|
|
|
|
|
|
|
####################################### |
76
|
|
|
|
|
|
|
# ATTENTION : Special calling convention and interface defined by MooseX::MungeHas. |
77
|
0
|
|
|
0
|
0
|
|
my $name = $_; # $_ contains the attribute NAME |
78
|
0
|
|
|
|
|
|
%_ = (@_, %_); # %_ contains the attribute SPECS or params for mungers (including ourselves), |
79
|
|
|
|
|
|
|
# @_ contains defaults. |
80
|
|
|
|
|
|
|
#say STDERR 'Dictionnary access!'; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my @dict = tidy_arrayify( delete $_{dict} ); |
83
|
0
|
|
|
|
|
|
my @src = tidy_arrayify( delete $_{src}, delete $_{src_dict}, @dict); |
84
|
0
|
|
|
|
|
|
my @dest = tidy_arrayify( delete $_{dest}, delete $_{dest_dict}, @dict); |
85
|
0
|
|
|
|
|
|
my $entry; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# multiple source dictionaries are supported. |
88
|
0
|
|
|
|
|
|
foreach my $src (@src) { |
89
|
|
|
|
|
|
|
#say STDERR ' Dictionnary : SOURCE lookup : ...'; |
90
|
0
|
0
|
|
|
|
|
next unless defined( $entry = exists $src->{$name} ? $src->{$name} : undef); |
|
|
0
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
do { $_{$_} = $entry->{$_} unless exists $_{$_} } for (keys %$entry); |
|
0
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# multiple destination dictionaries are supported. |
95
|
0
|
|
|
|
|
|
foreach my $dest (@dest) { |
96
|
|
|
|
|
|
|
#say STDERR ' Dictionnary : Updating DESTINATION : ...'; |
97
|
0
|
|
0
|
|
|
|
my $entry = $dest->{$name} //= +{}; |
98
|
0
|
|
|
|
|
|
$entry->{$_} = $_{$_} for (keys %_); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#say STDERR 'Dictionnary : about to return : ...'; |
102
|
0
|
0
|
|
|
|
|
wantarray ? (%_) : +{%_} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=pod |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=encoding UTF-8 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 NAME |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Banal::Moosy::Mungers - Provide several MUNGER functions that may be use in conjunction with C. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 VERSION |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
version 0.001 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 SYNOPSIS |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 DESCRIPTION |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=for stopwords haz ro |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
use Banal::Moosy::Mungers qw(mhs_specs); |
127
|
|
|
|
|
|
|
use Moose; |
128
|
|
|
|
|
|
|
use MooseX::MungeHas { |
129
|
|
|
|
|
|
|
haz => [ sub {; mhs_specs( is => 'ro', init_arg => undef, lazy => 1 ) }, |
130
|
|
|
|
|
|
|
] |
131
|
|
|
|
|
|
|
}; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=for stopwords TABULO |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This module provides several mungers that may be use in conjunction with C. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 EXPORT_OK |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over 4 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
mhs_lazy_ro |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
mhs_specs |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 SUPPORT |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Bugs may be submitted through L |
154
|
|
|
|
|
|
|
(or L). |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 AUTHOR |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Tabulo |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 CONTRIBUTOR |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=for stopwords Ayhan |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Ayhan |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Tabulo. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
171
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
__END__ |