blib/lib/Dist/Zilla/Plugin/Test/DiagINC.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 92.3% 60 / 65 CC 6 SCAR 9.1
CC
6
Cov
96%
munge_file
5.0
munge_files
2.0
BEGIN
1.0
CRAP 2.5
↑ Summary
1 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Dist::Zilla::Plugin::Test::DiagINC;
6 # ABSTRACT: Add Test::DiagINC to all .t files
7  
8 1 our $VERSION = '0.002';
9  
10 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 with(
12 'Dist::Zilla::Role::FileMunger',
13 'Dist::Zilla::Role::FileFinderUser' => {
14 default_finders => [':TestFiles'],
15 },
16 'Dist::Zilla::Role::PPI',
17 'Dist::Zilla::Role::PrereqSource',
18 );
19  
20 1 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Syntax::Keyword::Junction qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶sub munge_files {
Subroutine munge_files: called CC=2 SCAR=6.9
Pod undocumented
25 1 my ($self) = @_;
26 1 $self->munge_file($_) for grep { $_->name =~ /\.t$/ } @{ $self->found_files };
27 }
28  
29 1 ▶sub munge_file {
Subroutine munge_file: called CC=5 SCAR=16.1
Pod undocumented
30 1 my ( $self, $file ) = @_;
31  
32 1 my $document = $self->ppi_document_for_file($file);
33  
34 # using ::Comment is a hack for adding code copied from PkgVersion
35 1 my $add =
36 PPI::Token::Comment->new(q[use if $ENV{AUTOMATED_TESTING}, 'Test::DiagINC'; ]);
37  
38 1 my $was_munged;
39  
40 # XXX should errors get reported? -- xdg, 2014-02-04
41 1 eval {
42 1 my @includes = @{ $document->find('PPI::Statement::Include') };
43  
44 1 for my $s (@includes) {
45 4 ▶ next if $s->version;
Branch: 1 branch
BranchTrueFalseTotal
if $s->version 1 3 4
46 3 ▶ next if $s->module eq any(qw/strict warnings/);
Branch: 1 branch
BranchTrueFalseTotal
if $s->module eq any(("strict", "warnings")) 2 1 3
47 1 $was_munged = $s->first_token->insert_before($add);
48 1 last;
49 }
50 };
51  
52 1 ▶ if ($was_munged) {
Branch: 1 branch
BranchTrueFalseTotal
if ($was_munged) { } 1 0 1
53 1 $self->save_ppi_document_to_file( $document, $file );
54 1 $self->log_debug( [ "added Test::DiagINC line to %s", $file->name ] );
55 }
56 else {
57 0 $self->log( [ "skipping %s: couldn't add Test::DiagINC line", $file->name ] );
58 }
59  
60 }
61  
62 1 ▶sub register_prereqs {
Subroutine register_prereqs: called CC=1 SCAR=0.0
Pod undocumented
63 1 my $self = shift;
64  
65 1 $self->zilla->register_prereqs(
66 {
67 phase => 'test',
68 type => 'requires',
69 },
70 'Test::DiagINC' => '0.002',
71 );
72 }
73  
74 1 __PACKAGE__->meta->make_immutable;
75  
76 1 1;
77  
78  
79 # vim: ts=4 sts=4 sw=4 et:
80  
81 __END__
↑ Summary