RST/Spec.pm

filter: Statementstmt 90.4% 19 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.8% 26 / 28 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« RST/Input.pm ↑ Summary
1 package ICANN::RST::Spec;
2 # ABSTRACT: an object representing the RST test specifications.
3 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Mirror qw(mirror_file mirror_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use ICANN::RST::Case;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use ICANN::RST::ChangeLog;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use ICANN::RST::DataProvider;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use ICANN::RST::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use ICANN::RST::Input;
Subroutine BEGIN: called CC=1 SCAR=2.6
10 use ICANN::RST::Plan;
11 use ICANN::RST::Resource;
12 use ICANN::RST::Suite;
13 use ICANN::RST::Text;
14 use List::Util qw(pairmap);
15 use URI;
16 use YAML::XS;
17 use constant SCHEMA_VERSION => q{1.14.0};
18 use feature qw(say);
19 use strict;
20  
21 $YAML::XS::Boolean = q{JSON::PP};
22  
23 sub url_from_release {
24 my ($package, $release) = @_;
25  
26 return URI->new(sprintf(q{https://github.com/icann/rst-test-specs/releases/download/%s/rst-test-specs.yaml}, $release));
27 }
28  
29 sub current_version { shift->url_from_release(mirror_json(q{https://api.github.com/repos/icann/rst-test-specs/releases/latest})->{name}) }
30  
31 sub new_from_version {
32 my ($package, $version) = @_;
33 my $file = mirror_file($package->url_from_release($version));
34 return $file ? $package->new($file) : undef;
35 }
36  
37 sub new {
38 my ($package, $file) = @_;
39  
40 $file ||= mirror_file($package->current_version);
41  
42 my $self = bless(
43 {
44 'spec' => YAML::XS::LoadFile($file),
45 'file' => $file
46 },
47 $package,
48 );
49  
50 my $v = version->parse($self->spec->{'RST-Test-Plan-Schema-Version'});
51 croak(sprintf("Unsupported schema version '%s', must be '%s'", $v, SCHEMA_VERSION)) unless (SCHEMA_VERSION == $v);
52  
53 #
54 # precompile everything
55 #
56 $self->{'_preamble'} = ICANN::RST::Text->new($self->spec->{'Preamble'});
57 $self->{'_plans'} = [ sort { $a->order <=> $b->order } pairmap { ICANN::RST::Plan -> new($a, $b, $self) } %{$self->spec->{'Test-Plans'}} ];
58 $self->{'_suites'} = [ sort { $a->order <=> $b->order } pairmap { ICANN::RST::Suite -> new($a, $b, $self) } %{$self->spec->{'Test-Suites'}} ];
59 $self->{'_cases'} = [ sort { $a->id cmp $b->id } pairmap { ICANN::RST::Case -> new($a, $b, $self) } %{$self->spec->{'Test-Cases'}} ];
60 $self->{'_inputs'} = [ sort { $a->id cmp $b->id } pairmap { ICANN::RST::Input -> new($a, $b, $self) } %{$self->spec->{'Input-Parameters'}} ];
61 $self->{'_resources'} = [ sort { $a->id cmp $b->id } pairmap { ICANN::RST::Resource -> new($a, $b, $self) } %{$self->spec->{'Resources'}} ];
62 $self->{'_errors'} = [ sort { $a->id cmp $b->id } pairmap { ICANN::RST::Error -> new($a, $b, $self) } %{$self->spec->{'Errors'}} ];
63 $self->{'_providers'} = [ sort { $a->id cmp $b->id } pairmap { ICANN::RST::DataProvider -> new($a, $b, $self) } %{$self->spec->{'Data-Providers'}} ];
64  
65 return $self;
66 }
67  
68 sub changelog {
69 my $self = shift;
70  
71 my @log;
72  
73 foreach my $date (reverse(sort(keys(%{$self->spec->{'ChangeLog'}})))) {
74 push(@log, ICANN::RST::ChangeLog->new($date, $self->spec->{'ChangeLog'}->{$date}, $self));
75 }
76  
77 return @log;
78 }
79  
80 sub spec { $_[0]->{'spec'} }
81 sub schemaVersion { $_[0]->spec->{'RST-Test-Plan-Schema-Version'} }
82 sub version { $_[0]->spec->{'Version'} }
83 sub lastUpdated { $_[0]->spec->{'Last-Updated'} }
84 sub contactName { $_[0]->spec->{'Contact'}->{'Name'} }
85 sub contactOrg { $_[0]->spec->{'Contact'}->{'Organization'} }
86 sub contactEmail { $_[0]->spec->{'Contact'}->{'Email'} }
87 sub preamble { $_[0]->{'_preamble'} }
88 sub plans { @{ $_[0]->{'_plans'} } }
89 sub suites { @{ $_[0]->{'_suites'} } }
90 sub cases { @{ $_[0]->{'_cases'} } }
91 sub inputs { @{ $_[0]->{'_inputs'} } }
92 sub resources { @{ $_[0]->{'_resources'} } }
93 sub errors { @{ $_[0]->{'_errors'} } }
94 sub providers { @{ $_[0]->{'_providers'} } }
95 sub plan { my ($self, $id) = @_ ; return $self->find($id, $self->plans) }
96 sub suite { my ($self, $id) = @_ ; return $self->find($id, $self->suites) }
97 sub case { my ($self, $id) = @_ ; return $self->find($id, $self->cases) }
98 sub resource { my ($self, $id) = @_ ; return $self->find($id, $self->resources) }
99 sub error { my ($self, $id) = @_ ; return $self->find($id, $self->errors) }
100 sub input { my ($self, $id) = @_ ; return $self->find($id, $self->inputs) }
101 sub provider { my ($self, $id) = @_ ; return $self->find($id, $self->providers) }
102  
103 sub find {
104 my ($self, $needle, @haystack) = @_;
105  
106 foreach my $stick (@haystack) {
107 return $stick if ($stick->id eq $needle);
108 }
109  
110 carp("object '$needle' not found");
111  
112 return undef;
113 }
114  
115 1;
116  
117 __END__
118  
119 =pod
120  
121 =encoding UTF-8
122  
123 =head1 NAME
124  
125 ICANN::RST::Spec - an object representing the RST test specifications.
126  
127 =head1 VERSION
128  
129 version 0.03
130  
131 =head1 METHODS
132  
133 =head2 new($file)
134  
135 Constructor. C<$file> is the YAML file. If not provided, the most recent
136 version will be retrieved from
137 L<GitHub|https://github.com/icann-rst-test/specs/releases>.
138  
139 =head2 new_from_version($version);
140  
141 Returns an L<ICANN::RST::Spec> object corresponding to the version of the test
142 specs identified by C<$version>.
143  
144 =head2 schemaVersion()
145  
146 Returns a string containing the schema version of the spec file.
147  
148 =head2 version()
149  
150 Returns a string containing the version of the spec file.
151  
152 =head2 lastUpdated()
153  
154 Returns a string containing the date the spec was last updated.
155  
156 =head2 preamble()
157  
158 Returns a L<ICANN::RST::Text> object containing the preamble.
159  
160 =head2 changelog()
161  
162 Returns an array of L<ICANN::RST::ChangeLog> objects.
163  
164 =head2 contactName()
165  
166 Returns a string containing the contact name.
167  
168 =head2 contactOrg()
169  
170 Returns a string containing the contact organisation.
171  
172 =head2 contactEmail()
173  
174 Returns a string containing the contact email.
175  
176 =head2 plans()
177  
178 Returns an array of L<ICANN::RST::Plan> objects.
179  
180 =head2 plan($id)
181  
182 Returns the L<ICANN::RST::Plan> object with the given ID.
183  
184 =head2 suites()
185  
186 Returns an array of L<ICANN::RST::Suite> objects.
187  
188 =head2 suite($id)
189  
190 Returns the L<ICANN::RST::Suite> object with the given ID.
191  
192 =head2 resources()
193  
194 Returns an array of L<ICANN::RST::Resource> objects.
195  
196 =head2 resource($id)
197  
198 Returns the L<ICANN::RST::Resource> object with the given ID.
199  
200 =head2 cases()
201  
202 Returns an array of L<ICANN::RST::Case> objects.
203  
204 =head2 case($id)
205  
206 Returns the L<ICANN::RST::Case> object with the given ID.
207  
208 =head2 inputs()
209  
210 Returns an array of L<ICANN::RST::Input> objects.
211  
212 =head2 input($id)
213  
214 Returns the L<ICANN::RST::Input> object with the given ID.
215  
216 =head2 errors()
217  
218 Returns an array of L<ICANN::RST::Error> objects.
219  
220 =head2 error($id)
221  
222 =head2 providers()
223  
224 Returns an array of L<ICANN::RST::Error> objects.
225  
226 =head2 provider($id)
227  
228 Returns the L<ICANN::RST::DataProvider> object with the given ID.
229  
230 =head2 spec()
231  
232 Returns a hashref of the specification data structure.
233  
234 =head1 AUTHOR
235  
236 Gavin Brown <gavin.brown@icann.org>
237  
238 =head1 COPYRIGHT AND LICENSE
239  
240 This software is copyright (c) 2025 by Internet Corporation for Assigned Names and Number (ICANN).
241  
242 This is free software; you can redistribute it and/or modify it under
243 the same terms as the Perl 5 programming language system itself.
244  
245 =cut
« RST/Input.pm ↑ Summary