APIReference.pm

filter: Statementstmt 72.4% 71 / 98 Branchbran 44.4% 8 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 100% 2 / 2 totaltotal 68.7% 90 / 131 CC 10 SCAR 15.3
CC
10
Cov
68%
_dump_as_class
12.0
new
6.4
as_yaml_calltips
6.0
CRAP 4.6
« APIReference/Generator.pm ↑ Summary APIReference/V5_014_005.pm »
1 package Perl::APIReference;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Sereal::Decoder;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.24';
11  
12 use Class::XSAccessor
13 2 ▶ getters => {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 'index' => 'index',
15 'perl_version' => 'perl_version',
16 2 };
17  
18 0 ▶sub _par_loader_hint {
Subroutine _par_loader_hint: not called CC=1 SCAR=6.9
19 0 require Perl::APIReference::Generator;
20 0 require Perl::APIReference::V5_040_002;
21 }
22  
23 2 our %Perls;
24 SCOPE: {
25 # Generate list of supported Perl versions from shorthand.
26 2 my @perls = (
27 [40, 0..2],
28 [38, 0..4],
29 [36, 0..3],
30 [34, 0..3],
31 [32, 0..1],
32 [30, 0..3],
33 [28, 0..3],
34 [26, 0..4],
35 [24, 0..4],
36 [22, 0..4],
37 [20, 0..2],
38 [18, 0..2],
39 [16, 0..3],
40 [14, 0..4],
41 [12, 0..5],
42 [10, 0..1],
43 [8, 0..9],
44 [6, 0..2],
45 );
46  
47 2 foreach my $p (@perls) {
48 36 my $major = $p->[0];
49 36 foreach my $minor (@$p[1..$#$p]) {
50 154 my $v = sprintf("V5_%03u_%03u", $major, $minor);
51 154 my $num = sprintf("5.%03u", $major);
52 154 ▶ $num .= sprintf("%03u", $minor) if $minor > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $minor > 0 118 36 154
53 154 $Perls{$num} = $v;
54 }
55 }
56 };
57  
58 2 our $NewestAPI = '5.040002';
59 2 our $NewestStableAPI = '5.040002';
60  
61 # Aliases
62 2 $Perls{'5.04'} = $Perls{'5.040'};
63 2 $Perls{'5.040000'} = $Perls{'5.040'};
64 2 $Perls{'5.038000'} = $Perls{'5.038'};
65 2 $Perls{'5.036000'} = $Perls{'5.036'};
66 2 $Perls{'5.034000'} = $Perls{'5.034'};
67 2 $Perls{'5.032000'} = $Perls{'5.032'};
68 2 $Perls{'5.03'} = $Perls{'5.030'};
69 2 $Perls{'5.030000'} = $Perls{'5.030'};
70 2 $Perls{'5.028000'} = $Perls{'5.028'};
71 2 $Perls{'5.026000'} = $Perls{'5.026'};
72 2 $Perls{'5.024000'} = $Perls{'5.024'};
73 2 $Perls{'5.022000'} = $Perls{'5.022'};
74 2 $Perls{'5.02'} = $Perls{'5.020'};
75 2 $Perls{'5.020000'} = $Perls{'5.020'};
76 2 $Perls{'5.018000'} = $Perls{'5.018'};
77 2 $Perls{'5.016000'} = $Perls{'5.016'};
78 2 $Perls{'5.014000'} = $Perls{'5.014'};
79 2 $Perls{'5.012000'} = $Perls{'5.012'};
80 2 $Perls{'5.010000'} = $Perls{'5.010'};
81 2 $Perls{'5.01'} = $Perls{'5.010'};
82 2 $Perls{'5.008000'} = $Perls{'5.008'};
83 2 $Perls{'5.006000'} = $Perls{'5.006'};
84 #$Perls{'5.000'} = $Perls{5};
85  
86 99 ▶sub _get_class_name {
Subroutine _get_class_name: called CC=2 SCAR=7.1
87 99 my $class_or_self = shift;
88 99 my $version = shift;
89 99 ▶ return exists $Perls{$version} ? "Perl::APIReference::" . $Perls{$version} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $Perl::APIReference::Perls{$version} ? : 99 0 99
90 }
91  
92 99 ▶sub new {
Subroutine new: called CC=6 SCAR=18.6
Pod documented
93 99 my $class = shift;
94 99 my %args = @_;
95 99 my $perl_version = $args{perl_version};
96 99 ▶ croak("Need perl_version")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $perl_version 0 99 99
97 if not defined $perl_version;
98 99 ▶ $perl_version = $NewestStableAPI if lc($perl_version) eq "newest";
Branch: 1 branch
BranchTrueFalseTotal
if lc $perl_version eq "newest" 0 99 99
99 99 ▶ $perl_version = $NewestAPI if lc($perl_version) eq "newest_devel";
Branch: 1 branch
BranchTrueFalseTotal
if lc $perl_version eq "newest_devel" 0 99 99
100  
101 99 $perl_version = version->new($perl_version)->numify();
102 croak("Bad perl version '$perl_version'")
103 99 ▶ if not exists $Perls{$perl_version};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Perl::APIReference::Perls{$perl_version} 0 99 99
104  
105 99 my $classname = __PACKAGE__->_get_class_name($perl_version);
106 99 eval "require $classname;";
107 99 ▶ croak("Bad perl version ($@)") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 99 99
108  
109 99 return $classname->new(perl_version => $perl_version);
110 }
111  
112 0 ▶sub as_yaml_calltips {
Subroutine as_yaml_calltips: not called CC=2 SCAR=17.9
Pod documented
113 0 my $self = shift;
114  
115 0 my $index = $self->index();
116 0 my %toyaml;
117 0 foreach my $entry (keys %$index) {
118 my $yentry = {
119 cmd => '',
120 'exp' => $index->{$entry}{text},
121 0 };
122 0 $toyaml{$entry} = $yentry;
123 }
124 0 require YAML::Tiny;
125 0 return YAML::Tiny::Dump(\%toyaml);
126 }
127  
128 # only for ::Generator
129 0 ▶sub _new_from_parse {
Subroutine _new_from_parse: not called CC=1 SCAR=6.9
130 0 my $class = shift;
131  
132 0 return bless {@_} => $class;
133 }
134  
135 # only for ::Generator
136 0 ▶sub _dump_as_class {
Subroutine _dump_as_class: not called CC=3 SCAR=24.8
137 0 my $self = shift;
138 0 my $version = $self->perl_version;
139 0 my $classname = $self->_get_class_name($version);
140 0 ▶ if (not defined $classname) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $classname) 0 0 0
141 0 die "Can't determine class name for Perl version '$version'."
142 . " Do you need to add it to the list of supported versions first?";
143 }
144 0 my $file_name = $classname;
145 0 $file_name =~ s/^.*::([^:]+)$/$1.pm/;
146
147 0 require Sereal::Encoder;
148 0 my $data = $self->{'index'};
149 0 my $dump = Sereal::Encoder->new({
150 compress => Sereal::Encoder::SRL_ZSTD(),
151 compress_level => 22,
152 compress_threshold => 1,
153 dedupe_strings => 1,
154 sort_keys => 1,
155 })->encode($data);
156
157 0 ▶ open my $fh, '>', $file_name or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file_name or die $! 0 0 0
158 0 binmode $fh;
159 0 print $fh <<HERE;
160 package $classname;
161 use strict;
162 use warnings;
163 use Sereal::Decoder;
164 use parent 'Perl::APIReference';
165  
166 sub new {
167 my \$class = shift;
168 my \$pos = tell(*DATA);
169 binmode(*DATA);
170 local \$/ = undef;
171  
172 my \$data = <DATA>;
173 \$data =~ s/^\\s+//;
174  
175 my \$self = bless({
176 'index' => Sereal::Decoder::decode_sereal(\$data),
177 perl_version => '$version',
178 } => \$class);
179  
180 seek(*DATA, \$pos, 0);
181  
182 return \$self;
183 }
184  
185 1;
186  
187 HERE
188 0 print $fh "__DATA__\n";
189 0 print $fh $dump;
190 }
191  
192  
193 2 1;
194 __END__
« APIReference/Generator.pm ↑ Summary APIReference/V5_014_005.pm »