blib/lib/Acme/Damn.pm

filter: Statementstmt 100% 54 / 54 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 95.9% 71 / 74 CC 6 SCAR 11.5
CC
6
Cov
97%
import
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.1
↑ Summary Damn.xs »
1 package Acme::Damn;
2  
3 6 ▶use 5.000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use DynaLoader qw( AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 $VERSION = '0.08';
13 6 @ISA = qw( Exporter DynaLoader );
14 6 @EXPORT = qw( damn );
15 6 @EXPORT_OK = qw( bless );
16  
17 # ensure we aren't exposed to changes in inherited AUTOLOAD behaviour
18 6 *Acme::Damn::AUTOLOAD = *DynaLoader::AUTOLOAD;
19  
20  
21 sub import
22 {
23 9 ▶ my $class = shift;
Subroutine import: called CC=6 SCAR=17.9
24  
25 # check the unknown symbols to ensure they are 'safe'
26 9 my @bad = grep { /\W/o } @_;
27 9 ▶ if ( @bad ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bad) 3 6 9
28 # throw an error message informing the user where the problem is
29 3 my ( undef, $file , $line ) = caller 0;
30  
31 die sprintf( "Bad choice of symbol name%s %s for import at %s line %s\n"
32 , ( @bad == 1 ) ? '' : 's'
33 3 ▶ , join( ', ' , map { qq|'$_'| } @bad ) , $file , $line );
Branch: 1 branch
BranchTrueFalseTotal
@bad == 1 ? : 3 0 3
34 }
35  
36 # remove duplicates from the list of aliases, as well as those symbol
37 # names listed in @EXPORT
38 # - we keep @EXPORT_OK in a separate list since they are optionally
39 # requested at use() time
40 6 my @aliases = do { local %_;
41 6 @_{ @_ } = undef;
42 6 delete @_{ @EXPORT };
43 6 keys %_
44 };
45  
46 # 'import' the symbols into the host package
47 # - ensure 'EXPORT_OK' is correctly honoured
48 6 my %reserved = map { $_ => 1 } @EXPORT , @EXPORT_OK;
49 6 my @reserved = ();
50 6 my ( $pkg ) = caller 1;
51 6 foreach my $alias ( @aliases ) {
52 # if this alias is a reserved symbol as defined by @EXPORT et al.
53 # then add it to the list of symbols to export
54 21 ▶ $reserved{ $alias }
Branch: 1 branch
BranchTrueFalseTotal
$reserved{$alias} and push @reserved, $alias and next 1 20 21
Condition66%2/3
$reserved{$alias} and push @reserved, $alias
!ll&&!rl&&r
2001
MC/DC50%1/2
$reserved{$alias} and push @reserved, $alias
$reserved{$alias} push @reserved, $alias
Truth table66%2/3
A and B
A= $reserved{$alias}B= push @reserved, $alias
ABresult
0X0
100
111
55 and push @reserved , $alias
56 and next;
57  
58 # otherwise, create an alias for 'damn'
59 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 20 *{ $pkg . '::' . $alias } = sub {
62 30 ▶ my $ref = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
63 30 my ( undef , $file , $line ) = caller 1;
64  
65 # call damn() with the location of where this method was
66 # originally called
67 30 &{ __PACKAGE__ . '::damn' }( $ref , $alias , $file , $line );
68  
69 # NB: wanted to do something like
70 # goto \&{ __PACKAGE__ . '::damn' };
71 # having set the @_ array appropriately, but this caused a
72 # "Attempt to free unrefernced SV" error that I couldn't solve
73 # - I think it was to do with the @_ array
74 20 };
75 }
76  
77 # add the known symbols to @_
78 6 splice @_ , 0; push @_ , $class , @reserved;
79  
80 # run the "proper" import() routine
81 6 goto \&Exporter::import;
82 } # import()
83  
84  
85 6 bootstrap Acme::Damn $VERSION;
86  
87  
88 6 1; # end of module
89 __END__
↑ Summary Damn.xs »