line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
263008
|
use 5.006; # our |
|
5
|
|
|
|
|
13
|
|
2
|
5
|
|
|
5
|
|
18
|
use strict; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
83
|
|
3
|
5
|
|
|
5
|
|
15
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
301
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Gentoo::MetaEbuild::Spec::Base; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.000002'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: A Base Class for Gentoo MetaEbuild Specifications. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
2346
|
use Moose; |
|
5
|
|
|
|
|
1626262
|
|
|
5
|
|
|
|
|
39
|
|
14
|
5
|
|
|
5
|
|
33454
|
use MooseX::ClassAttribute qw( class_has ); |
|
5
|
|
|
|
|
362297
|
|
|
5
|
|
|
|
|
22
|
|
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
|
1123118
|
use File::ShareDir qw( module_dir ); |
|
5
|
|
|
|
|
5230
|
|
|
5
|
|
|
|
|
391
|
|
17
|
5
|
|
|
5
|
|
672
|
use Path::Tiny qw( path ); |
|
5
|
|
|
|
|
7899
|
|
|
5
|
|
|
|
|
283
|
|
18
|
5
|
|
|
5
|
|
2835
|
use MooseX::Types::Moose qw( Str CodeRef ); |
|
5
|
|
|
|
|
184225
|
|
|
5
|
|
|
|
|
45
|
|
19
|
5
|
|
|
5
|
|
20220
|
use MooseX::Types::Perl qw( VersionObject ); |
|
5
|
|
|
|
|
201987
|
|
|
5
|
|
|
|
|
70
|
|
20
|
5
|
|
|
5
|
|
11584
|
use MooseX::Types::Path::Tiny qw( AbsPath AbsDir ); |
|
5
|
|
|
|
|
500812
|
|
|
5
|
|
|
|
|
37
|
|
21
|
5
|
|
|
5
|
|
11267
|
use Scalar::Util qw( blessed ); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
349
|
|
22
|
5
|
|
|
5
|
|
3171
|
use MooseX::Has::Sugar qw( ro lazy_build rw coerce lazy ); |
|
5
|
|
|
|
|
2963
|
|
|
5
|
|
|
|
|
23
|
|
23
|
5
|
|
|
5
|
|
528
|
use version; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
33
|
|
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
5
|
|
293
|
use namespace::autoclean; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
52
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
class_has '_decoder' => ( |
28
|
|
|
|
|
|
|
isa => CodeRef, |
29
|
|
|
|
|
|
|
ro, lazy_build, |
30
|
|
|
|
|
|
|
traits => [qw( Code )], |
31
|
|
|
|
|
|
|
handles => { _decode => 'execute', }, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _build__decoder { |
35
|
4
|
|
|
4
|
|
1816
|
require JSON::MaybeXS; |
36
|
4
|
|
|
|
|
3405
|
my $decoder = JSON::MaybeXS->new()->utf8(1)->relaxed(1); |
37
|
|
|
|
|
|
|
return sub { |
38
|
10
|
|
|
10
|
|
418
|
$decoder->decode(shift); |
39
|
4
|
|
|
|
|
194
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
class_has '_spec_dir' => ( |
43
|
|
|
|
|
|
|
isa => AbsDir, |
44
|
|
|
|
|
|
|
rw, lazy_build, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _build__spec_dir { |
48
|
4
|
|
|
4
|
|
9
|
my ($self) = shift; |
49
|
4
|
|
|
|
|
6
|
my $classname; |
50
|
4
|
50
|
33
|
|
|
24
|
if ( ref $self && blessed $self ) { |
|
|
50
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
$classname = blessed $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ( ref $self ) { |
54
|
0
|
|
|
|
|
0
|
require Carp; |
55
|
|
|
|
|
|
|
## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars) |
56
|
0
|
|
|
|
|
0
|
Carp::confess q{$_[0] is not a Class/Object}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
4
|
|
|
|
|
5
|
$classname = $self; |
60
|
|
|
|
|
|
|
} |
61
|
4
|
|
|
|
|
22
|
return path( module_dir($classname) ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
class_has '_version' => ( |
65
|
|
|
|
|
|
|
isa => VersionObject, |
66
|
|
|
|
|
|
|
coerce, ro, lazy, default => sub { q{0.1.0} }, |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
class_has '_extension' => ( |
70
|
|
|
|
|
|
|
isa => Str, |
71
|
|
|
|
|
|
|
ro, lazy, default => sub { q{.json} }, |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
class_has '_schema_creator' => ( |
75
|
|
|
|
|
|
|
isa => CodeRef, |
76
|
|
|
|
|
|
|
ro, lazy_build, |
77
|
|
|
|
|
|
|
traits => [qw( Code )], |
78
|
|
|
|
|
|
|
handles => { _make_schema => 'execute', }, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
82
|
5
|
|
|
5
|
|
1829
|
no Moose; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
39
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _build__schema_creator { |
85
|
4
|
|
|
4
|
|
1467
|
require Data::Rx; |
86
|
4
|
|
|
|
|
27374
|
my $rx = Data::Rx->new(); |
87
|
|
|
|
|
|
|
return sub { |
88
|
10
|
|
|
10
|
|
33
|
$rx->make_schema(shift); |
89
|
4
|
|
|
|
|
53520
|
}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _opt_check { |
93
|
44
|
|
|
44
|
|
39
|
my ( $self, $opts ) = @_; |
94
|
44
|
100
|
|
|
|
140
|
if ( not exists $opts->{version} ) { |
|
|
100
|
|
|
|
|
|
95
|
1
|
|
|
|
|
37
|
$opts->{version} = $self->_version; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif ( blessed $opts->{version} ) { |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
6
|
|
|
|
|
56
|
$opts->{version} = version->parse( $opts->{version} ); |
102
|
|
|
|
|
|
|
} |
103
|
44
|
|
|
|
|
55
|
return $opts; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _spec_file { |
107
|
11
|
|
|
11
|
|
19
|
my ( $self, $opts ) = @_; |
108
|
11
|
|
|
|
|
20
|
$opts = $self->_opt_check($opts); |
109
|
11
|
|
|
|
|
393
|
return $self->_spec_dir->child( $opts->{version}->normal . $self->_extension ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _spec_data { |
113
|
11
|
|
|
11
|
|
15
|
my ( $self, $opts ) = @_; |
114
|
11
|
|
|
|
|
32
|
$opts = $self->_opt_check($opts); |
115
|
11
|
|
|
|
|
32
|
return $self->_decode( scalar $self->_spec_file($opts)->slurp() ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _schema { |
119
|
11
|
|
|
11
|
|
15
|
my ( $self, $opts ) = @_; |
120
|
11
|
|
|
|
|
25
|
$opts = $self->_opt_check($opts); |
121
|
11
|
|
|
|
|
31
|
return $self->_make_schema( $self->_spec_data($opts) ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub check { |
135
|
11
|
|
|
11
|
1
|
3918
|
my ( $self, $json_data, $opts ) = @_; |
136
|
11
|
|
|
|
|
38
|
$opts = $self->_opt_check($opts); |
137
|
11
|
|
|
|
|
32
|
return $self->_schema($opts)->check($json_data); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
__END__ |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=pod |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=encoding UTF-8 |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 NAME |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Gentoo::MetaEbuild::Spec::Base - A Base Class for Gentoo MetaEbuild Specifications. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 VERSION |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
version 1.000002 |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SYNOPSIS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
use Gentoo::MetaEbuild::Spec::Base; # or some derived class |
159
|
|
|
|
|
|
|
Gentoo::MetaEbuild::Spec::Base->check( $datastructure ); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This base-class only validates the most basic of basic, that the data is a { } using Data::Rx |
162
|
|
|
|
|
|
|
and using the shipped File::ShareDir v1.0.0.json spec to do that. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This will be more practical in consuming classes as they'll override selected methods/ship different spec files, |
165
|
|
|
|
|
|
|
but maintain the same useful interface. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 METHODS |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 check |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Packagename->check( $datastructure ); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Packagename->check( $datastructure, \%opts ); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Packagename->check( $datastructure, { version => '0.1.0' }); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 EXTENDING |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Extending should be this simple: |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
package FooBarBaz; |
182
|
|
|
|
|
|
|
use Moose; |
183
|
|
|
|
|
|
|
extends 'Gentoo::MetaEbuild::Spec::Base'; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
and then ship a directory of Data::Rx spec files as the Module ShareDir for that module. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 TESTING |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
The only fun thing with testing is the File::ShareDir directory hasn't been installed yet, but its simple to get around. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
use FindBin; |
194
|
|
|
|
|
|
|
use Path::Tiny qw( path ); |
195
|
|
|
|
|
|
|
use Gentoo::MetaEbuild::Spec::Base; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Gentoo::MetaEbuild::Spec::Base->_spec_dir( |
198
|
|
|
|
|
|
|
path($FindBin::Bin)->parent->child('share') |
199
|
|
|
|
|
|
|
); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# Code as per usual. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my $shareroot = path($FindBin::Bin)->parent(); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 AUTHOR |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Kent Fredric <kentnl@cpan.org> |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Kent Fredric <kentnl@cpan.org>. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
214
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |