File Coverage

blib/lib/Math/NumSeq/OEIS.pm
Criterion Covered Total %
statement 32 35 91.4
branch 2 4 50.0
condition 1 3 33.3
subroutine 9 10 90.0
pod 3 3 100.0
total 47 55 85.4


line stmt bran cond sub pod time code
1             # Copyright 2011, 2012, 2013, 2014, 2016 Kevin Ryde
2              
3             # This file is part of Math-NumSeq.
4             #
5             # Math-NumSeq is free software; you can redistribute it and/or modify
6             # it under the terms of the GNU General Public License as published by the
7             # Free Software Foundation; either version 3, or (at your option) any later
8             # version.
9             #
10             # Math-NumSeq is distributed in the hope that it will be useful, but
11             # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12             # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13             # for more details.
14             #
15             # You should have received a copy of the GNU General Public License along
16             # with Math-NumSeq. If not, see .
17              
18             package Math::NumSeq::OEIS;
19 2     2   5874 use 5.004;
  2         4  
20 2     2   6 use strict;
  2         2  
  2         26  
21 2     2   6 use Carp;
  2         1  
  2         85  
22              
23 2     2   6 use vars '$VERSION','@ISA';
  2         1  
  2         76  
24             $VERSION = 72;
25              
26 2     2   397 use Math::NumSeq;
  2         2  
  2         66  
27             @ISA = ('Math::NumSeq');
28              
29             # uncomment this to run the ### lines
30             #use Smart::Comments;
31              
32              
33             # use constant name => Math::NumSeq::__('OEIS');
34 2     2   7 use constant description => Math::NumSeq::__('OEIS sequence, by its A-number. There\'s code for some sequences, others look in ~/OEIS directory for downloaded files A123456.internal, A123456.html and/or b123456.txt.');
  2         1  
  2         7  
35 2     2   12 use constant characteristic_integer => 1;
  2         2  
  2         416  
36              
37             # recalculated each time for updated file min/max
38             sub parameter_info_array {
39 65     65 1 738 require Math::NumSeq::OEIS::Catalogue;
40             return [
41 65         125 { name => 'anum',
42             type => 'string',
43             display => Math::NumSeq::__('OEIS A-number'),
44             type_hint => 'oeis_anum',
45             width => 8,
46             minimum => Math::NumSeq::OEIS::Catalogue->anum_first,
47             maximum => Math::NumSeq::OEIS::Catalogue->anum_last,
48             default => 'A000290', # Squares, an arbitrary choice
49             },
50             ];
51             }
52             ### parameter_info_array parameter_info_array()
53              
54             sub oeis_anum {
55 0     0 1 0 my ($self) = @_;
56 0         0 return $self->{'oeis_anum'};
57             }
58              
59             sub new {
60 2     2 1 1845 my ($class, %options) = @_;
61             ### Values-OEIS: @_
62              
63 2         4 my $anum = $options{'anum'};
64 2 50       8 if (! defined $anum) {
65 0         0 $anum = parameter_info_array()->[0]->{'default'};
66             }
67             ### $anum
68              
69 2         468 require Math::NumSeq::OEIS::Catalogue;
70 2   33     11 my $info = Math::NumSeq::OEIS::Catalogue->anum_to_info($anum)
71             || croak 'No data for OEIS sequence ',$anum;
72             ### $info
73              
74 2         40 my $numseq_class = $info->{'class'};
75 2         2 my $parameters = $info->{'parameters'};
76 2         418 require Module::Load;
77 2         723 Module::Load::load($numseq_class);
78 2 50       30 return $numseq_class->new (%options, ($parameters ? @$parameters : ()));
79             }
80              
81             1;
82             __END__