XSBuilder/MapUtil.pm

filter: Statementstmt 30.7% 47 / 153 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 50.0% 12 / 24 Podpod 0.0% 0 / 6 totaltotal 23.8% 59 / 247 CC 35 SCAR 33.5
CC
35
Cov
22%
map_files
110.0
write_map_file
30.0
readline
20.0
CRAP 28.4
« XSBuilder/CallbackMap.pm ↑ Summary XSBuilder/PODTemplate.pm »
1 package ExtUtils::XSBuilder::MapUtil;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Data::Dumper ;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use IO::Handle ;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use ExtUtils::XSBuilder::TypeMap ;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @EXPORT_OK = qw(list_first disabled_reason
11 function_table structure_table
12 callback_table callback_hash
13 );
14  
15 1 our @ISA = qw(Exporter);
16  
17 1 my %disabled_map = (
18 '!' => 'disabled or not yet implemented',
19 '~' => 'implemented but not auto-generated',
20 '-' => 'likely never be available to Perl',
21 '>' => '"private" to apache',
22 '?' => 'unclassified',
23 '+' => 'automaticly added',
24 );
25  
26 # ============================================================================
27  
28 1 my $function_table = [];
29  
30 0 ▶sub function_table {
Subroutine function_table: not called CC=3 SCAR=16.9
Pod undocumented
31 0 ▶ return $function_table if @$function_table;
Branch: 1 branch
BranchTrueFalseTotal
if @$function_table 0 0 0
32  
33 0 my $parsesource = shift -> parsesource_objects ;
34  
35 0 $function_table = [] ;
36  
37 0 foreach my $src (@$parsesource) {
38 0 require $src -> pm_path ('FunctionTable.pm') ;
39 1 ▶no strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 0 push @$function_table, @${$src -> package . '::FunctionTable'} ;
41 1 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 }
43  
44 0 return $function_table;
45 }
46  
47 # ============================================================================
48  
49 1 my $callback_table = [];
50  
51 0 ▶sub callback_table {
Subroutine callback_table: not called CC=3 SCAR=16.9
Pod undocumented
52 0 ▶ return $callback_table if @$callback_table;
Branch: 1 branch
BranchTrueFalseTotal
if @$callback_table 0 0 0
53 0 my $parsesource = shift -> parsesource_objects ;
54  
55 0 $callback_table = [] ;
56  
57 0 foreach my $src (@$parsesource) {
58 0 require $src -> pm_path ('CallbackTable.pm') ;
59 1 ▶no strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 0 push @$callback_table, @${$src -> package . '::CallbackTable'} ;
61 1 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 }
63 0 return $callback_table;
64 }
65  
66  
67 # ============================================================================
68  
69 1 my $callback_hash ;
70  
71 0 ▶sub callback_hash {
Subroutine callback_hash: not called CC=2 SCAR=17.9
Pod undocumented
72 0 ▶ return $callback_hash if $callback_hash ;
Branch: 1 branch
BranchTrueFalseTotal
if $callback_hash 0 0 0
73  
74 0 my %callbacks = map { $_->{name}, $_ } @{ callback_table(shift) };
75  
76 0 $callback_hash = \%callbacks ;
77 }
78  
79 # ============================================================================
80  
81 1 my $structure_table = [];
82  
83 0 ▶sub structure_table {
Subroutine structure_table: not called CC=3 SCAR=16.9
Pod undocumented
84 0 ▶ return $structure_table if @$structure_table;
Branch: 1 branch
BranchTrueFalseTotal
if @$structure_table 0 0 0
85 0 $structure_table = [] ;
86  
87 0 my $parsesource = shift -> parsesource_objects ;
88 0 foreach my $src (@$parsesource) {
89 0 require $src -> pm_path ('StructureTable.pm') ;
90 1 ▶no strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 0 push @$structure_table, @${$src -> package . '::StructureTable'} ;
92 1 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 }
94 0 return $structure_table;
95 }
96  
97 # ============================================================================
98  
99 0 ▶sub disabled_reason {
Subroutine disabled_reason: not called CC=2 SCAR=17.9
Pod undocumented
100 0 ▶ $disabled_map{+shift} || 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
$disabled_map{shift()} or "unknown" 0 0 0
101 }
102  
103  
104 # ============================================================================
105  
106 0 ▶sub list_first (&@) {
Subroutine list_first: not called CC=3 SCAR=24.8
Pod undocumented
107 0 my $code = shift;
108  
109 0 for (@_) {
110 0 ▶ return $_ if $code->();
Branch: 1 branch
BranchTrueFalseTotal
if &$code() 0 0 0
111 }
112  
113 0 undef;
114 }
115  
116 # ============================================================================
117  
118 package ExtUtils::XSBuilder::MapBase;
119  
120 1 *function_table = \&ExtUtils::XSBuilder::function_table;
121 1 *structure_table = \&ExtUtils::XSBuilder::structure_table;
122  
123 0 ▶sub readline {
Subroutine readline: not called CC=4 SCAR=30.0
124 0 my $fh = shift;
125  
126 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = CORE::readline $fh)) 0 0 0
127 0 chomp;
128 0 s/^\s+//; s/\s+$//;
129 0 s/^\#.*//;
130 0 s/\s*\#.*//;
131  
132 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
133  
134 0 ▶ if (s:\\$::) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/\\$//) 0 0 0
135 0 my $cur = $_;
136 0 $_ = $cur . $fh->readline;
137 0 return $_;
138 }
139  
140 0 return $_;
141 }
142 }
143  
144 1 my $map_classes = join '|', qw(type structure function callback);
145  
146 0 ▶sub map_files {
Subroutine map_files: not called CC=10 SCAR=47.0
147 0 my $self = shift;
148 0 ▶ my $package = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
149  
150 0 my($wanted) = $package =~ /($map_classes)/io;
151  
152 0 my(@dirs) = ($self -> {wrapxs} -> xs_map_dir(), $self -> {wrapxs} -> xs_glue_dirs());
153  
154 0 my @files;
155  
156 0 ▶ my @searchdirs = map { -d "$_/maps" ? "$_/maps" : $_ } @dirs ;
Branch: 1 branch
BranchTrueFalseTotal
-d "$_/maps" ? : 0 0 0
157 0 for my $dir (@searchdirs) {
158 0 ▶ opendir my $dh, $dir or warn "opendir $dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or warn "opendir ${dir}: $!" 0 0 0
159  
160 0 for (readdir $dh) {
161 0 ▶ next unless /\.map$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\.map$/ 0 0 0
162  
163 0 my $file = "$dir/$_";
164  
165 0 ▶ if ($wanted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted) 0 0 0
166 0 ▶ next unless $file =~ /$wanted/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /$wanted/i 0 0 0
167 }
168  
169 #print "$package => $file\n";
170 0 push @files, $file;
171 }
172  
173 0 closedir $dh;
174 }
175  
176 0 ▶ print 'WARNING: No *_' . lc($wanted) . ".map file found in @searchdirs\n" if (!@files) ;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 0 0 0
177 0 return @files;
178 }
179  
180 0 ▶sub new_map_file {
Subroutine new_map_file: not called CC=4 SCAR=30.0
181 0 my $self = shift;
182 0 ▶ my $package = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
183  
184 0 my($wanted) = $package =~ /($map_classes)/io;
185  
186 0 my(@dirs) = ($self -> {wrapxs} -> xs_map_dir(), $self -> {wrapxs} -> xs_glue_dirs());
187  
188 0 my @files;
189  
190 0 ▶ my @searchdirs = map { -d "$_/maps" ? "$_/maps" : $_ } @dirs ;
Branch: 1 branch
BranchTrueFalseTotal
-d "$_/maps" ? : 0 0 0
191
192  
193 0 ▶ if (!@searchdirs)
Branch: 1 branch
BranchTrueFalseTotal
unless (@searchdirs) 0 0 0
194 {
195 0 print "WARNING: No maps directory found\n" ;
196 0 return undef ;
197 }
198  
199
200 0 return $searchdirs[0] . '/new_' . lc($wanted) . '.map' ;
201 }
202  
203  
204 0 ▶sub parse_keywords {
Subroutine parse_keywords: not called CC=4 SCAR=30.0
205 0 my($self, $line) = @_;
206 0 my %words;
207  
208 0 for my $pair (split /\s+/, $line) {
209 0 my($key, $val) = split /=/, $pair;
210  
211 0 ▶ unless ($key and $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key and $val) 0 0 0
Condition0%0/3
$key and $val
!ll&&!rl&&r
000
MC/DC0%0/2
$key and $val
$key $val
Truth table0%0/3
A and B
A= $keyB= $val
ABresult
0X0
100
111
212 0 die "parse error ($ExtUtils::XSBuilder::MapFile line $.)";
213 }
214  
215 0 $words{$key} = $val;
216 }
217  
218 0 %words;
219 }
220  
221 0 ▶sub parse_map_files {
Subroutine parse_map_files: not called CC=3 SCAR=24.8
222 0 my($self) = @_;
223  
224 0 my $map = {};
225  
226 0 for my $file (map_files($self)) {
227 0 print "Parse $file...\n" ;
228 0 ▶ open my $fh, $file or die "open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $file or die "open ${file}: $!" 0 0 0
229 0 local $ExtUtils::XSBuilder::MapFile = $file;
230 0 bless $fh, __PACKAGE__;
231 0 $self->parse($fh, $map);
232 0 close $fh;
233 }
234  
235 0 return $map;
236 }
237  
238 0 ▶sub write_map_file {
Subroutine write_map_file: not called CC=5 SCAR=34.0
239 0 my($self, $newentries, $prefix) = @_;
240  
241 0 ▶ return if (!$newentries || !@$newentries) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $newentries and @$newentries 0 0 0
Condition0%0/3
$newentries and @$newentries
!ll&&!rl&&r
000
MC/DC0%0/2
$newentries and @$newentries
$newentries @$newentries
Truth table0%0/3
A and B
A= $newentriesB= @$newentries
ABresult
0X0
100
111
242  
243 0 ▶ my $file = $self -> new_map_file or die ;
Branch: 1 branch
BranchTrueFalseTotal
my $file = $self->new_map_file or die 0 0 0
244  
245 0 print "Write $file...\n" ;
246 0 ▶ open my $fh, '>>', $file or die "open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>", $file or die "open ${file}: $!" 0 0 0
247 0 local $ExtUtils::XSBuilder::MapFile = $file;
248 #bless $fh, __PACKAGE__;
249  
250 0 $fh -> print ( "\n### Added " . scalar(localtime) . " ###\n\n" );
251  
252 0 $self->write($fh, $newentries, $prefix);
253 0 close $fh;
254 }
255  
256  
257 1 1;
258 __END__
« XSBuilder/CallbackMap.pm ↑ Summary XSBuilder/PODTemplate.pm »