PerlPackage2PlantUMLClassDiagram/Package.pm

filter: Statementstmt 98.8% 82 / 83 Branchbran 70.0% 21 / 30 Conditioncond 78.9% 15 / 19 MC/DCmcdc 58.3% 7 / 12 Subroutinesub 100% 18 / 18 Podpod 0.0% 0 / 10 totaltotal 83.1% 143 / 172 CC 24 SCAR 15.6
CC
24
Cov
89%
parent_packages
11.4
_arguments
7.1
document
2.0
CRAP 4.8
↑ Summary PerlPackage2PlantUMLClassDiagram/Repository.pm »
1 package App::PerlPackage2PlantUMLClassDiagram::Package;
2 3 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use PPI::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Text::MicroTemplate::DataSection 'render_mt';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
10 13 my ($class, $source) = @_;
11  
12 13 ▶ unless (-f $source) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $source) 1 12 13
13 1 die "file not exist: $source";
14 }
15  
16 bless {
17 12 source => $source,
18 }, $class;
19 }
20  
21 13 ▶sub source {
Subroutine source: called CC=1 SCAR=0.0
Pod undocumented
22 13 my ($self) = @_;
23  
24 13 $self->{source};
25 }
26  
27 44 ▶sub document {
Subroutine document: called CC=2 SCAR=7.1
Pod undocumented
28 44 my ($self) = @_;
29  
30 44 ▶ $self->{document} ||= PPI::Document->new($self->source);
Condition66%2/3
$self->{"document"} ||= "PPI::Document"->new($self->source)
l!l&&r!l&&!r
32120
MC/DC0%0/2
$self->{"document"} ||= "PPI::Document"->new($self->source)
$self->{"document"} "PPI::Document"->new($self->source)
Truth table66%2/3
A ||= B
A= $self->{"document"}B= "PPI::Document"->new($self->source)
ABresult
1X1
011
000
31 }
32  
33 13 ▶sub package_name {
Subroutine package_name: called CC=2 SCAR=6.9
Pod undocumented
34 13 my ($self) = @_;
35  
36 13 my $package = $self->document->find_first('PPI::Statement::Package');
37 13 ▶ return unless $package;
Branch: 1 branch
BranchTrueFalseTotal
unless $package 1 12 13
38 12 $package->namespace;
39 }
40  
41 7 ▶sub parent_packages {
Subroutine parent_packages: called CC=9 SCAR=24.3
Pod undocumented
42 7 my ($self) = @_;
43  
44 7 ▶ my $includes = $self->document->find('PPI::Statement::Include') || [];
Condition100%2/2
$self->document->find('PPI::Statement::Include') || []
l!l
25
MC/DC100%1/1
$self->document->find('PPI::Statement::Include') || []
$self->document->find('PPI::Statement::Include')
Truth table100%2/2
A
A= $self->document->find('PPI::Statement::Include')
Aresult
11
00
45 7 ▶ return [] unless $includes;
Branch: 1 branch
BranchTrueFalseTotal
unless $includes 0 7 7
46  
47 7 my $parent_packages = [];
48  
49 # see also: App::PRT::Command::RenameClass
50 7 for my $statement (@$includes) {
51 2 ▶ next unless defined $statement->pragma;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $statement->pragma 0 2 2
52 2 ▶ next unless $statement->pragma =~ /^parent|base$/; # only 'use parent' and 'use base' are supported
Branch: 1 branch
BranchTrueFalseTotal
unless $statement->pragma =~ /^parent|base$/u 0 2 2
53  
54 # schild(2) is 'Foo' of use parent Foo
55 2 my $parent = $statement->schild(2);
56  
57 2 ▶ if ($parent->isa('PPI::Token::Quote')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parent->isa('PPI::Token::Quote')) { } 0 2 2
elsif ($parent->isa('PPI::Token::QuoteLike::Words')) { } 2 0 2
58 # The 'literal' method is not implemented by ::Quote::Double or ::Quote::Interpolate.
59 0 ▶ push @$parent_packages, $parent->can('literal') ? $parent->literal : $parent->string;
Branch: 1 branch
BranchTrueFalseTotal
$parent->can('literal') ? : 0 0 0
60 } elsif ($parent->isa('PPI::Token::QuoteLike::Words')) {
61 # use parent qw(A B C) pattern
62 # literal is array when QuoteLike::Words
63 2 push @$parent_packages, $parent->literal;
64 }
65 }
66  
67 7 $parent_packages;
68 }
69  
70 23 ▶sub _methods {
Subroutine _methods: called CC=2 SCAR=6.9
71 23 my ($self) = @_;
72  
73 23 ▶ $self->document->find('PPI::Statement::Sub') || [];
Branch: 1 branch
BranchTrueFalseTotal
$self->document->find("PPI::Statement::Sub") or [] 22 1 23
74 }
75  
76 64 ▶sub _arguments ($) {
Subroutine _arguments: called CC=7 SCAR=19.6
77 64 my ($sub) = @_;
78  
79 64 my $variable = $sub->find_first('PPI::Statement::Variable');
80 64 ▶ return () unless $variable;
Branch: 1 branch
BranchTrueFalseTotal
unless $variable 2 62 64
81  
82 62 my $list = $variable->find_first('PPI::Structure::List');
83 62 ▶ return () unless $list;
Branch: 1 branch
BranchTrueFalseTotal
unless $list 0 62 62
84  
85 62 ▶ my $symbols = $list->find('PPI::Token::Symbol') || [];
Condition50%1/2
$list->find('PPI::Token::Symbol') || []
l!l
620
MC/DC0%0/1
$list->find('PPI::Token::Symbol') || []
$list->find('PPI::Token::Symbol')
Truth table50%1/2
A
A= $list->find('PPI::Token::Symbol')
Aresult
11
00
86 62 ▶ return () unless @$symbols;
Branch: 1 branch
BranchTrueFalseTotal
unless @$symbols 0 62 62
87 62 ▶ my $receiver = shift @$symbols if $symbols->[0]->content eq '$self' || $symbols->[0]->content eq '$class';
Branch: 1 branch
BranchTrueFalseTotal
if $symbols->[0]->content eq "\$self" or $symbols->[0]->content eq "\$class" 60 2 62
Condition100%3/3
$symbols->[0]->content eq "\$self" or $symbols->[0]->content eq "\$class"
l!l&&r!l&&!r
40202
MC/DC100%2/2
$symbols->[0]->content eq "\$self" or $symbols->[0]->content eq "\$class"
$symbols->[0]->content eq "\$self" $symbols->[0]->content eq "\$class"
Truth table100%3/3
A or B
A= $symbols->[0]->content eq "\$self"B= $symbols->[0]->content eq "\$class"
ABresult
1X1
011
000
88 62 ($receiver, @$symbols);
89 }
90  
91 18 ▶sub _method_signature ($) {
Subroutine _method_signature: called CC=1 SCAR=0.0
92 18 my ($sub) = @_;
93  
94 18 my (undef, @arguments) = _arguments($sub);
95  
96 18 "@{[ $sub->name ]}(@{[ join ', ', @arguments ]})";
97 }
98  
99 6 ▶sub static_methods {
Subroutine static_methods: called CC=2 SCAR=7.0
Pod undocumented
100 6 my ($self) = @_;
101 5 [ map { _method_signature $_ } grep {
102 14 my ($receiver) = _arguments $_;
103 14 ▶ $receiver && $receiver eq '$class';
Condition66%2/3
$receiver && $receiver eq '$class'
!ll&&!rl&&r
095
MC/DC50%1/2
$receiver && $receiver eq '$class'
$receiver $receiver eq '$class'
Truth table66%2/3
A && B
A= $receiverB= $receiver eq '$class'
ABresult
0X0
100
111
104 6 } @{$self->_methods} ];
105 }
106  
107 10 ▶sub public_methods {
Subroutine public_methods: called CC=2 SCAR=6.9
Pod undocumented
108 10 my ($self) = @_;
109  
110 10 [ map { _method_signature $_ } grep { index($_->name, '_') != 0 } grep {
111 18 my ($receiver) = _arguments $_;
112 18 ▶ !$receiver || $receiver eq '$self';
Condition100%3/3
!$receiver || $receiver eq '$self'
l!l&&r!l&&!r
2115
MC/DC100%2/2
!$receiver || $receiver eq '$self'
!$receiver $receiver eq '$self'
Truth table100%3/3
not(A) || B
A= !$receiverB= $receiver eq '$self'
ABresult
1X1
011
000
113 10 } @{$self->_methods} ];
114 }
115  
116 6 ▶sub private_methods {
Subroutine private_methods: called CC=2 SCAR=7.0
Pod undocumented
117 6 my ($self) = @_;
118  
119 3 [ map { _method_signature $_ } grep { index($_->name, '_') == 0 } grep {
120 14 my ($receiver) = _arguments $_;
121 14 ▶ !$receiver || $receiver eq '$self';
Condition66%2/3
!$receiver || $receiver eq '$self'
l!l&&r!l&&!r
095
MC/DC50%1/2
!$receiver || $receiver eq '$self'
!$receiver $receiver eq '$self'
Truth table66%2/3
not(A) || B
A= !$receiverB= $receiver eq '$self'
ABresult
1X1
011
000
122 6 } @{$self->_methods} ];
123 }
124  
125 6 ▶sub to_class_syntax {
Subroutine to_class_syntax: called CC=2 SCAR=6.9
Pod undocumented
126 6 my ($self) = @_;
127  
128 6 my $package_name = $self->package_name;
129  
130 6 ▶ return '' unless $package_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $package_name 1 5 6
131  
132 5 render_mt('class_syntax', {
133 package_name => $self->package_name,
134 static_methods => $self->static_methods,
135 public_methods => $self->public_methods,
136 private_methods => $self->private_methods,
137 });
138 }
139  
140 6 ▶sub to_inherit_syntax {
Subroutine to_inherit_syntax: called CC=2 SCAR=6.9
Pod undocumented
141 6 my ($self) = @_;
142  
143 6 my $parent_packages = $self->parent_packages;
144  
145 6 ▶ return '' unless @$parent_packages;
Branch: 1 branch
BranchTrueFalseTotal
unless @$parent_packages 5 1 6
146  
147 1 render_mt('inherit_syntax', {
148 package_name => $self->package_name,
149 parent_packages => $parent_packages,
150 });
151 }
152  
153 3 1;
154 __DATA__
↑ Summary PerlPackage2PlantUMLClassDiagram/Repository.pm »