blib/lib/PPI/XS.pm

filter: Statementstmt 91.1% 41 / 45 Branchbran 54.1% 13 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 80.2% 61 / 76 SCAR 0.1
CC
1
Cov
78%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary XS.xs »
1 package PPI::XS;
2  
3 # See POD at end for documentation
4  
5 2 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # In the unlikely case they someone tries to manually load
10 # PPI::XS without PPI itself loaded, they probably MEAN for us
11 # to load in PPI as well. Pretty useless otherwise, because we
12 # need to _overwrite_ the PPI methods, we can't have it loading
13 # after we do.
14 2 ▶use PPI 1.000 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # Define compatibility information
17 2 ▶use vars qw{$VERSION $PM_COMPATIBLE %EXCLUDE};
Subroutine BEGIN: called CC=1 SCAR=0.0
18 BEGIN {
19 2 ▶ $VERSION = '0.902';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 $PM_COMPATIBLE = '0.844';
21 2 %EXCLUDE = ();
22 }
23  
24 # Does the main package define the minimum set of variables?
25 2 ▶return 1 unless defined $PPI::VERSION;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PPI::VERSION 0 2 2
26 2 ▶return 1 unless defined $PPI::XS_COMPATIBLE;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PPI::XS_COMPATIBLE 0 2 2
27 2 ▶return 1 if $PPI::VERSION =~ /_/;
Branch: 1 branch
BranchTrueFalseTotal
if $PPI::VERSION =~ /_/ 0 2 2
28  
29 # Are we compatible with the main package
30 2 ▶return 1 unless $VERSION > $PPI::XS_COMPATIBLE;
Branch: 1 branch
BranchTrueFalseTotal
unless $PPI::XS::VERSION > $PPI::XS_COMPATIBLE 0 2 2
31 2 ▶return 1 unless $PPI::VERSION > $PM_COMPATIBLE;
Branch: 1 branch
BranchTrueFalseTotal
unless $PPI::VERSION > $PPI::XS::PM_COMPATIBLE 0 2 2
32  
33 # Provide an option to manually disable this package
34 2 ▶return 1 if $PPI::XS_DISABLE;
Branch: 1 branch
BranchTrueFalseTotal
if $PPI::XS_DISABLE 0 2 2
35  
36 # If we aren't EXACTLY the same version, determine
37 # which functions we might need to exclude.
38 2 ▶if ( $VERSION > $PPI::VERSION ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($PPI::XS::VERSION > $PPI::VERSION) { } 0 2 2
elsif ($PPI::XS::VERSION < $PPI::VERSION) { } 2 0 2
39 # We are newer, we have the option of excluding functions
40 ### NOTE: Nothing to exclude in this version
41 # %EXCLUDE = map { $_ => 1 } qw{};
42 # (example) PPI::Element::exclude_this
43 } elsif ( $VERSION < $PPI::VERSION ) {
44 # It is newer, it has the option of excluding functions
45 2 ▶ if ( @PPI::XS_EXCLUDE ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@PPI::XS_EXCLUDE) 0 2 2
46 # It as defined things for us to exclude
47 0 %EXCLUDE = map { $_ => 1 } @PPI::XS_EXCLUDE;
48 }
49 }
50  
51 # Load the XS functions
52 2 XSLoader::load( 'PPI::XS' => $VERSION );
53  
54 # Find all the functions in PPI::XS
55 2 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
56 2 ▶foreach ( sort grep { /^_PPI_/ and defined &{"PPI::XS::$_"} } keys %{"PPI::XS::"} ) {
Branch: 1 branch
BranchTrueFalseTotal
/^_PPI_/ and defined &{"PPI::XS::$_";} 8 14 22
57 # Prepare
58 8 ▶ /^_(\w+?)__(\w+)$/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^_(\w+?)__(\w+)$/ or next 0 8 8
59 8 my ($class, $function) = ($1, $2);
60 8 $class =~ s/_/::/g;
61  
62 8 ▶ if ( $EXCLUDE{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI::XS::EXCLUDE{$_}) { } 0 8 8
63 # Remove the un-needed function.
64 # The primary purpose of this is to recover the memory
65 # occupied by the useless functions, but has the
66 # additional benefit of allowing us to detect which
67 # functions were actually mapped in by examining the
68 # names of the functions remaining in the PPI::XS symbol
69 # table.
70 0 delete ${"PPI::XS::"}{$_};
71 } else {
72 # Map in the function
73 8 *{"${class}::${function}"} = *{"PPI::XS::$_"};
74 }
75 }
76  
77 2 1;
78  
79 __END__
↑ Summary XS.xs »