File Coverage

blib/lib/Math/OEIS/Names.pm
Criterion Covered Total %
statement 34 36 94.4
branch 6 10 60.0
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 51 57 89.4


line stmt bran cond sub pod time code
1             # Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Kevin Ryde
2              
3             # This file is part of Math-OEIS.
4             #
5             # Math-OEIS is free software; you can redistribute it and/or modify it
6             # under the terms of the GNU General Public License as published by the Free
7             # Software Foundation; either version 3, or (at your option) any later
8             # version.
9             #
10             # Math-OEIS 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-OEIS. If not, see .
17              
18             package Math::OEIS::Names;
19 3     3   75196 use 5.006;
  3         20  
20 3     3   15 use strict;
  3         6  
  3         57  
21 3     3   28 use warnings;
  3         7  
  3         94  
22 3     3   17 use Carp 'croak';
  3         6  
  3         158  
23              
24 3     3   854 use Math::OEIS::SortedFile;
  3         6  
  3         229  
25             our @ISA = ('Math::OEIS::SortedFile');
26              
27             # uncomment this to run the ### lines
28             # use Smart::Comments;
29              
30             our $VERSION = 14;
31              
32 3     3   22 use constant base_filename => 'names';
  3         5  
  3         648  
33              
34             sub line_split {
35 4     4 1 2539 my ($self, $line) = @_;
36             ### Names line_split(): $line
37 4 100       27 $line =~ /^((A\d+)\s*)(.*)/
38             or return; # perhaps comment lines
39 3         24 return (substr($line,0,length($2)),
40             substr($line,length($1),length($3)));
41             }
42              
43             use constant::defer _HAVE_ENCODE => sub {
44 1 50       23 eval { require Encode; 1 } || 0;
  1         584  
  1         10192  
45 3     3   1429 };
  3         2405  
  3         38  
46              
47             sub anum_to_name {
48 1     1 1 8 my ($self, $anum) = @_;
49             ### Names anum_to_name(): $anum
50 1         8 my $line = $self->anum_to_line($anum);
51 1 50       5 if (! defined $line) { return undef; }
  0         0  
52              
53 1         3 my ($got_anum, $name) = $self->line_split($line);
54 1 50       5 if ($got_anum ne $anum) { return undef; }
  0         0  
55              
56 1 50       5 if (_HAVE_ENCODE) {
57 1         46 $name = Encode::decode('utf8', $name, Encode::FB_PERLQQ());
58             }
59 1         48 return $name;
60             }
61              
62              
63             # sub anum_to_name {
64             # my ($class, $anum) = @_;
65             # $anum =~ /^A[0-9]+$/ or die "Bad A-number: ", $anum;
66             # return `zgrep -e ^$anum $ENV{HOME}/OEIS/names.gz`;
67             # }
68              
69             1;
70             __END__