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