AutoXS.pm

filter: Statementstmt 92.3% 24 / 26 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 94.2% 33 / 35 CC 1 SCAR 0.3
CC
1
Cov
92%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« AutoXS/Accessor.pm ↑ Summary
1 package AutoXS;
2  
3 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 our $VERSION = '0.04';
8  
9 #require XSLoader;
10 #XSLoader::load('AutoXS', $VERSION);
11  
12 1 ▶use vars qw/%ScanClasses $Debug/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use B::Utils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use B::Generate;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 use Module::Pluggable
20 0 ▶ except => qr/(?:::b?lib::|^AutoXS::Header$)/,
Subroutine BEGIN: called CC=1 SCAR=2.6
21 search_path => 'AutoXS',
22 sub_name => 'plugins',
23 0 ;
24  
25 use vars qw/@ISA/;
26 sub import {
27 my $class = shift;
28 my ($callerpkg) = caller;
29 return if $callerpkg =~ /^AutoXS/;
30  
31 my @importclasses;
32  
33 if (@_ == 1) {
34 # load all plugins
35 if ($_[0] eq ':all') {
36 push @importclasses, $class->plugins();
37 }
38 else {
39 croak("Invalid arguments to 'use $class;'");
40 }
41 }
42 elsif (@_ == 0) {
43 if ($class =~ /^AutoXS::(.+)$/) {
44 # called on a plugin class (inherited)
45 # apply that plugin
46 push @importclasses, $class;
47 }
48 }
49 else {
50 my %args = @_;
51 $AutoXS::Debug = 1 if $args{debug};
52  
53 return if not defined $args{plugins};
54  
55 push @importclasses, (ref($args{plugins}) ? @{$args{plugins}} : ($args{plugins}));
56 }
57  
58 foreach my $importclass (@importclasses) {
59 $importclass = "AutoXS::$importclass" if not $importclass =~ /^AutoXS::/;
60 eval "require $importclass;";
61 if ($@) {
62 die "Cannot load AutoXS scanner plugin '$importclass': $@";
63 }
64 warn "Registering AutoXS scanner class '$importclass' for scanning '$callerpkg'.\n" if $AutoXS::Debug;
65 $importclass->register_class($callerpkg, $importclass);
66 }
67 }
68  
69 sub register_class {
70 my $class = shift;
71 $class = shift if $class =~ /^AutoXS/;
72 die "Cannot register undefined class!" if not defined $class;
73 my @plugins = @_;
74  
75 foreach my $plugin (@plugins) {
76 $ScanClasses{$plugin}{$class} = 1;
77 }
78 }
79  
80 sub get_symbol {
81 my $class = shift;
82 my $edit_pkg = shift;
83
84 no strict 'refs';
85 my $sym = \%{$edit_pkg."::"};
86  
87 return $sym;
88 }
89  
90 1;
91 __END__
« AutoXS/Accessor.pm ↑ Summary