blib/lib/CXC/Number/Sequence.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.4% 17 / 18 Podpod 100% 8 / 8 totaltotal 95.8% 70 / 73 CC 2 SCAR 1.5
CC
2
Cov
96%
_convert
2.0
pdl
2.0
BEGIN
1.0
CRAP 1.2
« blib/lib/CXC/Number/Sequence/Role/BigNum.pm ↑ Summary Build »
1 package CXC::Number::Sequence;
2  
3 # ABSTRACT: Numerical Sequence Generation
4  
5 11 ▶use v5.28;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use CXC::Number::Sequence::Types qw( Sequence );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use CXC::Number::Sequence::Failure -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use CXC::Number::Sequence::Utils qw( load_class );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 11 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 11 our $VERSION = '0.12';
17  
18 11 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 11 ▶use MooX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # subclass should define
23 11 has _raw_elements => (
24 is => 'lazy',
25 init_arg => 'elements',
26 isa => Sequence,
27 required => 1,
28 coerce => 1,
29 );
30  
31  
32 ▶sub _convert ( $self, $bignum ) {
Subroutine _convert: called CC=2 SCAR=6.9
33 9 require Ref::Util;
34  
35 return Ref::Util::is_plain_arrayref( $bignum )
36 9 ▶ ? [ map { $_->numify } $bignum->@* ]
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::is_plain_arrayref($bignum) ? : 3 6 9
37 : $bignum->numify;
38 }
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49 ▶sub elements ( $self ) {
Subroutine elements: called CC=1 SCAR=0.0
Pod documented
50 5 $self->_convert( $self->_raw_elements );
51 }
52  
53  
54  
55  
56  
57  
58  
59  
60  
61 ▶sub nelem ( $self ) {
Subroutine nelem: called CC=1 SCAR=0.0
Pod documented
62 4 scalar $self->_raw_elements->@*;
63 }
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75 ▶sub spacing ( $self ) {
Subroutine spacing: called CC=1 SCAR=0.0
Pod documented
76 1 my $elements = $self->_raw_elements;
77 1 my @spacing = map { $elements->[$_] - $elements->[ $_ - 1 ] } 1 .. ( $self->nelem - 1 );
78 1 return $self->_convert( \@spacing );
79 }
80  
81  
82  
83  
84  
85  
86  
87  
88  
89 ▶sub min ( $self ) {
Subroutine min: called CC=1 SCAR=0.0
Pod documented
90 4 return $self->_convert( $self->_raw_elements->[0] );
91 }
92  
93  
94  
95  
96  
97  
98  
99  
100  
101 ▶sub max ( $self ) {
Subroutine max: called CC=1 SCAR=0.0
Pod documented
102 4 return $self->_convert( $self->_raw_elements->[-1] );
103 }
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123 ▶sub build ( $, $type, %options ) {
Subroutine build: called CC=1 SCAR=0.0
Pod documented
124 5 load_class( $type )->new( %options );
125 }
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141 ▶sub bignum ( $self ) {
Subroutine bignum: called CC=1 SCAR=0.0
Pod documented
142 2 require Moo::Role;
143 2 return Moo::Role->apply_roles_to_object(
144 __PACKAGE__->new( elements => $self->_raw_elements ),
145 __PACKAGE__ . '::Role::BigNum',
146 );
147 }
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161 ▶sub pdl ( $self ) {
Subroutine pdl: not called CC=1 SCAR=6.9
Pod documented
162 0 require Moo::Role;
163 0 return Moo::Role->apply_roles_to_object(
164 __PACKAGE__->new( elements => $self->_raw_elements ),
165 __PACKAGE__ . '::Role::PDL',
166 );
167 }
168  
169  
170 #
171 # This file is part of CXC-Number
172 #
173 # This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory.
174 #
175 # This is free software, licensed under:
176 #
177 # The GNU General Public License, Version 3, June 2007
178 #
179  
180 11 1;
181  
182 __END__
183  
184 =pod
185  
186 =for :stopwords Diab Jerius Smithsonian Astrophysical Observatory nelem bignum pdl
187  
188 =head1 NAME
189  
190 CXC::Number::Sequence - Numerical Sequence Generation
191  
192 =head1 VERSION
193  
194 version 0.12
195  
196 =head1 SYNOPSIS
197  
198 use CXC::Number::Sequence;
199  
200 CXC::Number::Sequence->build( $type, %options );
201  
202 =head1 DESCRIPTION
203  
204 This is an entry point for building sequences of numbers.
205  
206 B<WARNING>
207  
208 Currently, a sequence is a subclass of C<CXC::Number::Sequence>, but
209 this may change to a role based relationship.
210  
211 =head2 Constraints
212  
213 At present sequences are not lazily built. This can easily be
214 accommodated and iterators added.
215  
216 =head1 CONSTRUCTORS
217  
218 =head2 build
219  
220 $sequence = CXC::Number::Sequence->build( $class, %options );
221  
222 Construct a sequence of type C<$class>, where C<$class> is a subclass of
223 B<CXC::Number::Sequence>. If C<$class> is in the C<CXC::Number::Sequence>
224 namespace, only the relative class name is required, e.g.
225  
226 linear => CXC::Number::Sequence::Linear
227  
228 (note that C<$class> is converted to I<CamelCase>; input words should be separated by a C<_>).
229  
230 C<build> will first attempt to load C<$class> in the
231 C<CXC::Number::Sequence> namespace, and if not present will assume
232 C<$class> is a full package name.
233  
234 =head1 METHODS
235  
236 =head2 elements
237  
238 $array_ref = $sequence->elements;
239  
240 Return the sequence elements as a reference to an array of Perl
241 numbers.
242  
243 =head2 nelem
244  
245 $nelem = $sequence->nelem;
246  
247 The number of elements in the sequence.
248  
249 =head2 spacing
250  
251 $spacing = $sequence->spacing;
252  
253 Return the spacing between elements as a reference to an array of Perl
254 numbers.
255  
256 =head2 min
257  
258 $min = $sequence->min;
259  
260 Returns the minimum bound of the sequence as a Perl number.
261  
262 =head2 max
263  
264 $max = $sequence->max;
265  
266 Returns the maximum bound of the sequence as a Perl number.
267  
268 =head2 bignum
269  
270 $elements = $sequence->bignum->elements;
271  
272 Returns an object which returns copies of the internal
273 L<Math::BigFloat> objects for the following methods
274  
275 elements -> Array[Math::BigFloat]
276 spacing -> Array[Math::BigFloat]
277 min -> Math::BigFloat
278 max -> Math::BigFloat
279  
280 =head2 pdl
281  
282 $elements = $sequence->pdl->elements;
283  
284 Returns an object which returns piddles for the following methods
285  
286 elements -> piddle
287 spacing -> piddle
288  
289 =head1 INTERNALS
290  
291 =head1 SUPPORT
292  
293 =head2 Bugs
294  
295 Please report any bugs or feature requests to bug-cxc-number@rt.cpan.org or through the web interface at: L<https://rt.cpan.org/Public/Dist/Display.html?Name=CXC-Number>
296  
297 =head2 Source
298  
299 Source is available at
300  
301 https://gitlab.com/djerius/cxc-number
302  
303 and may be cloned from
304  
305 https://gitlab.com/djerius/cxc-number.git
306  
307 =head1 SEE ALSO
308  
309 Please see those modules/websites for more information related to this module.
310  
311 =over 4
312  
313 =item *
314  
315 L<CXC::Number|CXC::Number>
316  
317 =item *
318  
319 L<CXC::Number::Grid|CXC::Number::Grid>
320  
321 =item *
322  
323 L<CXC::Number::Sequence::Linear|CXC::Number::Sequence::Linear>
324  
325 =item *
326  
327 L<CXC::Number::Sequence::Ratio|CXC::Number::Sequence::Ratio>
328  
329 =item *
330  
331 L<CXC::Number::Sequence::Fixed|CXC::Number::Sequence::Fixed>
332  
333 =back
334  
335 =head1 AUTHOR
336  
337 Diab Jerius <djerius@cpan.org>
338  
339 =head1 COPYRIGHT AND LICENSE
340  
341 This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory.
342  
343 This is free software, licensed under:
344  
345 The GNU General Public License, Version 3, June 2007
346  
347 =cut
« blib/lib/CXC/Number/Sequence/Role/BigNum.pm ↑ Summary Build »