lib/Perl/ToPerl6/Transformer/ModuleSpecific/Exporter.pm

filter: Statementstmt 48.4% 31 / 64 Branchbran 9.0% 2 / 22 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 77.7% 14 / 18 Podpod 42.8% 3 / 7 totaltotal 40.3% 50 / 124 CC 20 SCAR 37.8
CC
20
Cov
35%
transform
117.7
ppi_rhs_list_values
30.0
__ANON__
6.0
CRAP 43.6
« lib/Perl/ToPerl6/Transformer/Operators/FormatOperators.pm ↑ Summary lib/Perl/ToPerl6/Transformer/Pragmas/RewriteConstants.pm »
1 package Perl::ToPerl6::Transformer::ModuleSpecific::Exporter;
2  
3 17 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 ▶use Perl::ToPerl6::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use Perl::ToPerl6::Utils::PPI qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
10 ppi_list_elements
11 insert_trailing_whitespace
12 17 };
13  
14 17 ▶use base 'Perl::ToPerl6::Transformer';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #-----------------------------------------------------------------------------
17  
18 17 Readonly::Scalar my $DESC => q{Add 'is export' and 'is export(:tag)' declarations to subroutines};
19 17 Readonly::Scalar my $EXPL => q{Add 'is export' and 'is export(:tag)' declarations to subroutines};
20  
21 #-----------------------------------------------------------------------------
22  
23 31 ▶sub run_before { return 'Operators::FormatOperators' }
Subroutine run_before: called CC=1 SCAR=0.0
Pod undocumented
24 38 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
25 29 ▶sub default_necessity { return $NECESSITY_HIGHEST }
Subroutine default_necessity: called CC=1 SCAR=0.0
Pod documented
26 26 ▶sub default_themes { return qw( tweaks ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
27 4 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
28  
29 #-----------------------------------------------------------------------------
30  
31 0 ▶sub ppi_rhs_list_values {
Subroutine ppi_rhs_list_values: not called CC=5 SCAR=34.0
Pod undocumented
32 0 my ($elem) = @_;
33 0 my @values;
34 0 ▶ if ( $elem->snext_sibling and
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->snext_sibling and $elem->snext_sibling->isa("PPI::Token::Operator") and $elem->snext_sibling->content eq "=" and $elem->snext_sibling->snext_sibling) 0 0 0
Condition0%0/9
$elem->snext_sibling and $elem->snext_sibling->isa("PPI::Token::Operator") and $elem->snext_sibling->content eq "=" and $elem->snext_sibling->snext_sibling
!ll&&!rl&&r
000
$elem->snext_sibling and $elem->snext_sibling->isa("PPI::Token::Operator") and $elem->snext_sibling->content eq "="
!ll&&!rl&&r
000
$elem->snext_sibling and $elem->snext_sibling->isa("PPI::Token::Operator")
!ll&&!rl&&r
000
MC/DC0%0/4
$elem->snext_sibling and $elem->snext_sibling->isa("PPI::Token::Operator") and $elem->snext_sibling->content eq "=" and $elem->snext_sibling->snext_sibling
$elem->snext_sibling $elem->snext_sibling->isa("PPI::Token::Operator") $elem->snext_sibling->content eq "=" $elem->snext_sibling->snext_sibling
Truth table0%0/5
A and B and C and D
A= $elem->snext_siblingB= $elem->snext_sibling->isa("PPI::Token::Operator")C= $elem->snext_sibling->content eq "="D= $elem->snext_sibling->snext_sibling
ABCDresult
0XXX0
10XX0
110X0
11100
11111
35 $elem->snext_sibling->isa('PPI::Token::Operator') and
36 $elem->snext_sibling->content eq '=' and
37 $elem->snext_sibling->snext_sibling ) {
38 0 push @values, ppi_list_elements(
39 $elem->snext_sibling->snext_sibling
40 );
41 }
42 0 return @values;
43 }
44  
45 #
46 # All subs in @EXPORT will be marked with 'is export(:MANDATORY)'
47 # All subs in @EXPORT_OK will be marked with just 'is export'
48 # All subs in a tag of %EXPORT_TAGS will be marked with 'is export(:tag)'
49 # (there's a default ':ALL' tag that may be useful)
50 # ( 'is export(:a :b)' works for multiple tag names, I guess)
51  
52 4 ▶sub transform {
Subroutine transform: called CC=12 SCAR=47.7
Pod undocumented
53 4 my ($self, $elem, $doc) = @_;
54 32 ▶ return unless $doc->find( sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
55 32 ▶ $_[1]->isa('PPI::Statement::Include') and
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Statement::Include") and $_[1]->schild(1)->content =~ / ^ Exporter /x 0 32 32
56 $_[1]->schild(1)->content =~ m< ^ Exporter >x
57 4 ▶ } );
Branch: 1 branch
BranchTrueFalseTotal
unless $doc->find(sub { $_[1]->isa("PPI::Statement::Include") and $_[1]->schild(1)->content =~ / ^ Exporter /x; } ) 4 0 4
58  
59 0 my $subroutine_tags = {};
60  
61 0 ▶ my $export = $doc->find( sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
62 0 ▶ $_[1]->isa('PPI::Token::Symbol') and
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Symbol") and $_[1]->content eq "\@EXPORT" 0 0 0
63 $_[1]->content eq '@EXPORT'
64 0 } );
65  
66 0 ▶ my $export_ok = $doc->find( sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
67 0 ▶ $_[1]->isa('PPI::Token::Symbol') and
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Symbol") and $_[1]->content eq "\@EXPORT_OK" 0 0 0
68 $_[1]->content eq '@EXPORT_OK'
69 0 } );
70  
71 0 ▶ my $export_tags = $doc->find( sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
72 0 ▶ $_[1]->isa('PPI::Token::Symbol') and
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Symbol") and $_[1]->content eq "%EXPORT_TAGS" 0 0 0
73 $_[1]->content eq '%EXPORT_TAGS'
74 0 } );
75  
76 0 my $subs = $doc->find('PPI::Statement::Sub');
77  
78 0 ▶ if ( @$export ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$export) 0 0 0
79 0 for my $_elem ( @$export ) {
80 0 for ( ppi_rhs_list_values($_elem) ) {
81 0 push @{ $subroutine_tags->{$_} }, 'MANDATORY'
82 }
83 }
84 }
85 #
86 # XXX The code here assumes that @EXPORT and @EXPORT_OK are disjoint sets.
87 #
88 0 ▶ if ( @$export_ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$export_ok) 0 0 0
89 0 for my $_elem ( @$export_ok ) {
90 0 for ( ppi_rhs_list_values($_elem) ) {
91 0 $subroutine_tags->{$_} = 1;
92 }
93 }
94 }
95  
96 0 for my $sub ( @$subs ) {
97 0 ▶ next unless $sub->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $sub->name 0 0 0
98 0 ▶ next unless exists $subroutine_tags->{$sub->name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$subroutine_tags{$sub->name} 0 0 0
99 0 my $export_tags = '';
100 0 ▶ if ( ref $subroutine_tags->{$sub->name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$subroutine_tags{$sub->name}) 0 0 0
101 $export_tags = ' (' .
102 0 join( ', ', map { ":$_" }
103 0 @{ $subroutine_tags->{$sub->name} } ) .
104 ')';
105 }
106 0 $sub->schild(1)->insert_after(
107 PPI::Token::Attribute->new('is export' . $export_tags)
108 );
109 0 insert_trailing_whitespace($sub->schild(1));
110 }
111  
112 0 return $self->transformation( $DESC, $EXPL, $elem );
113 }
114  
115 17 1;
116  
117 #-----------------------------------------------------------------------------
118  
119 __END__
« lib/Perl/ToPerl6/Transformer/Operators/FormatOperators.pm ↑ Summary lib/Perl/ToPerl6/Transformer/Pragmas/RewriteConstants.pm »