File Coverage

blib/lib/PPI/XS.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 19 19 100.0


line stmt bran cond sub pod time code
1             package PPI::XS; # git description: release-0.904-4-g378ef4e
2              
3             # See POD at end for documentation
4              
5 2     2   176352 use 5.005;
  2         12  
6 2     2   7 use strict;
  2         4  
  2         32  
7 2     2   7 use XSLoader;
  2         2  
  2         38  
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     2   379 use PPI 1.000 ();
  2         96854  
  2         246  
15              
16             # Define compatibility information
17             our $VERSION = '0.910';
18             our $PM_COMPATIBLE = '0.844';
19             our %EXCLUDE = ();
20              
21             # Does the main package define the minimum set of variables?
22             return 1 unless defined $PPI::VERSION;
23             return 1 unless defined $PPI::XS_COMPATIBLE;
24             return 1 if $PPI::VERSION =~ /_/;
25              
26             # Are we compatible with the main package
27             return 1 unless $VERSION > $PPI::XS_COMPATIBLE;
28             return 1 unless $PPI::VERSION > $PM_COMPATIBLE;
29              
30             # Provide an option to manually disable this package
31             return 1 if $PPI::XS_DISABLE;
32              
33             # If we aren't EXACTLY the same version, determine
34             # which functions we might need to exclude.
35             if ( $VERSION > $PPI::VERSION ) {
36             # We are newer, we have the option of excluding functions
37             ### NOTE: Nothing to exclude in this version
38             # %EXCLUDE = map { $_ => 1 } qw{};
39             # (example) PPI::Element::exclude_this
40             } elsif ( $VERSION < $PPI::VERSION ) {
41             # It is newer, it has the option of excluding functions
42             if ( @PPI::XS_EXCLUDE ) {
43             # It as defined things for us to exclude
44             %EXCLUDE = map { $_ => 1 } @PPI::XS_EXCLUDE;
45             }
46             }
47              
48             # Load the XS functions
49             XSLoader::load( 'PPI::XS' => $VERSION );
50              
51             # Find all the functions in PPI::XS
52 2     2   12 no strict 'refs';
  2         4  
  2         328  
53             foreach ( sort grep { /^_PPI_/ and defined &{"PPI::XS::$_"} } keys %{"PPI::XS::"} ) {
54             # Prepare
55             /^_(\w+?)__(\w+)$/ or next;
56             my ($class, $function) = ($1, $2);
57             $class =~ s/_/::/g;
58              
59             if ( $EXCLUDE{$_} ) {
60             # Remove the un-needed function.
61             # The primary purpose of this is to recover the memory
62             # occupied by the useless functions, but has the
63             # additional benefit of allowing us to detect which
64             # functions were actually mapped in by examining the
65             # names of the functions remaining in the PPI::XS symbol
66             # table.
67             delete ${"PPI::XS::"}{$_};
68             } else {
69             # Map in the function
70             *{"${class}::${function}"} = *{"PPI::XS::$_"};
71             }
72             }
73              
74             1;
75              
76             __END__