File Coverage

blib/lib/Math/NumSeq/OEIS/Catalogue/Plugin.pm
Criterion Covered Total %
statement 33 33 100.0
branch 6 6 100.0
condition 12 16 75.0
subroutine 9 9 100.0
pod 0 6 0.0
total 60 70 85.7


line stmt bran cond sub pod time code
1             # Copyright 2011, 2012, 2013, 2014 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::Catalogue::Plugin;
19 3     3   40 use 5.004;
  3         8  
20 3     3   10 use strict;
  3         3  
  3         60  
21              
22 3     3   9 use vars '$VERSION';
  3         3  
  3         1060  
23             $VERSION = 72;
24              
25             # uncomment this to run the ### lines
26             #use Smart::Comments;
27              
28             my %anum_to_info_hashref;
29             sub anum_to_info_hashref {
30 3     3 0 3 my ($class) = @_;
31             ### anum_to_info_hashref(): $class
32             return ($anum_to_info_hashref{$class} ||=
33 3   100     13 { map { $_->{'anum'} => $_ } @{$class->info_arrayref} });
  923         1391  
  1         8  
34             }
35              
36             sub anum_to_info {
37 2     2 0 2 my ($class, $anum) = @_;
38 2 100       11 foreach my $anum ($anum,
39             # A0123456 shortened to A123456
40             ($anum =~ /A0(\d{6})/ ? "A$1" : ())) {
41 3   100     6 return ($class->anum_to_info_hashref->{$anum} || next);
42             }
43             }
44              
45             sub anum_after {
46 130     130 0 103 my ($class, $after_anum) = @_;
47             ### $after_anum
48 130         89 my $ret;
49 130         95 foreach my $info (@{$class->info_arrayref}) {
  130         259  
50             ### after info: $info
51 59995 100 100     172754 if ($info->{'anum'} gt $after_anum
      33        
52             && (! defined $ret || $ret gt $info->{'anum'})) {
53 390         361 $ret = $info->{'anum'};
54             }
55             }
56 130         438 return $ret;
57             }
58             sub anum_before {
59 130     130 0 104 my ($class, $before_anum) = @_;
60             ### $before_anum
61 130         88 my $ret;
62 130         88 foreach my $info (@{$class->info_arrayref}) {
  130         218  
63 59995 100 100     175161 if ($info->{'anum'} lt $before_anum
      33        
64             && (! defined $ret || $ret lt $info->{'anum'})) {
65 520         442 $ret = $info->{'anum'};
66             }
67             }
68 130         409 return $ret;
69             }
70              
71             sub anum_first {
72 195     195 0 168 my ($class) = @_;
73 195         365 return $class->anum_after ('A000000');
74             }
75             sub anum_last {
76 195     195 0 173 my ($class) = @_;
77 195         291 return $class->anum_before('A9999999'); # 7-digits
78             }
79              
80             1;
81             __END__