lib/CodeGen/Protection/Format/Perl.pm

filter: Statementstmt 86.9% 20 / 23 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 80.5% 29 / 36 CC 5 SCAR 13.4
CC
5
Cov
77%
_tidy
6.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
« lib/CodeGen/Protection/Role.pm ↑ Summary blib/lib/Test/CodeGen/Protection.pm »
1 package CodeGen::Protection::Format::Perl;
2  
3 # ABSTRACT: Safely rewrite parts of Perl documents
4  
5 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 with qw(CodeGen::Protection::Role);
8  
9 5 our $VERSION = '0.06';
10  
11 25 ▶sub _tidy {
Subroutine _tidy: called CC=5 SCAR=18.0
12 25 my ( $self, $code ) = @_;
13 25 ▶ return $code unless my $perltidy = $self->tidy;
Branch: 1 branch
BranchTrueFalseTotal
unless my $perltidy = $self->tidy 20 5 25
14 5 require Perl::Tidy;
15 5 my @perltidy;
16 5 ▶ if ( '1' ne $perltidy ) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 ne $perltidy) 0 5 5
17 0 ▶ unless ( -e $perltidy ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $perltidy) 0 0 0
18 0 croak("Cannot find perltidyrc file: $perltidy");
19 }
20 0 @perltidy = ( perltidyrc => $perltidy );
21 }
22  
23 5 my ( $stderr, $tidied );
24  
25 # need to clear @ARGV or else Perl::Tidy thinks you're trying
26 # to provide a filename and dies
27 5 local @ARGV;
28 5 ▶ Perl::Tidy::perltidy(
Branch: 1 branch
BranchTrueFalseTotal
Perl::Tidy::perltidy("source", \$code, "destination", \$tidied, "stderr", \$stderr, @perltidy) and die "Perl::Tidy error: $stderr" 0 5 5
29 source => \$code,
30 destination => \$tidied,
31 stderr => \$stderr,
32 @perltidy,
33 ) and die "Perl::Tidy error: $stderr";
34  
35 5 return $tidied;
36 }
37  
38 # For both the _start_marker_format() and the _end_marker_format(), the first
39 # '%s' is the version number if it's being added to the document. It's a
40 # version regex (_version_re()) if it's being used to match the start or end
41 # marker.
42  
43 # The second '%s' is the md5 sum if it's being added to the document. It's a
44 # captured md5 regex ([0-9a-f]{32}) if it's being used to match the start or
45 # end marker.
46  
47 76 ▶sub _start_marker_format {
Subroutine _start_marker_format: called CC=1 SCAR=0.0
48 76 '#<<< %s %s. Do not touch any code between this and the end comment. Checksum: %s';
49 }
50  
51 76 ▶sub _end_marker_format {
Subroutine _end_marker_format: called CC=1 SCAR=0.0
52 76 '#>>> %s %s. Do not touch any code between this and the start comment. Checksum: %s';
53 }
54  
55 5 1;
56  
57 __END__
« lib/CodeGen/Protection/Role.pm ↑ Summary blib/lib/Test/CodeGen/Protection.pm »