File Coverage

blib/lib/App/MigrateToTest2V0/Rule/AvoidNameConflictWithTestDeep.pm
Criterion Covered Total %
statement 21 43 48.8
branch 0 4 0.0
condition 0 8 0.0
subroutine 7 10 70.0
pod 0 1 0.0
total 28 66 42.4


line stmt bran cond sub pod time code
1             package App::MigrateToTest2V0::Rule::AvoidNameConflictWithTestDeep;
2 1     1   815 use strict;
  1         2  
  1         26  
3 1     1   4 use warnings;
  1         3  
  1         21  
4 1     1   452 use parent 'App::MigrateToTest2V0::Rule';
  1         288  
  1         5  
5 1     1   474 use PPIx::Utils qw(is_function_call);
  1         225697  
  1         196  
6 1     1   13 use List::Util qw(any);
  1         2  
  1         90  
7 1     1   1333 use Test::Deep ();
  1         11411  
  1         38  
8 1     1   10 use constant TEST_DEEP_EXPORTS => [@Test::Deep::EXPORT];
  1         3  
  1         381  
9              
10             sub apply {
11 0     0 0   my ($class, $doc) = @_;
12              
13             my $stmts = $doc->find(sub {
14 0     0     my (undef, $elem) = @_;
15 0   0       return $elem->isa('PPI::Statement::Include') && $elem->module eq 'Test::Deep';
16 0           });
17 0 0         return unless $stmts;
18              
19             my $tokens = $doc->find(sub {
20 0     0     my (undef, $elem) = @_;
21 0   0       return $elem->isa('PPI::Token::Word') && any { $elem->content eq $_ } @{ TEST_DEEP_EXPORTS() };
22 0           });
23 0   0       $tokens ||= [];
24              
25 0           for my $token (@$tokens) {
26 0 0         next unless is_function_call($token);
27 0           $token->set_content('Test::Deep::' . $token->content);
28             }
29              
30             # replace use
31 0           for my $stmt (@$stmts) {
32 0           my $module_name_token = $stmt->schild(1);
33              
34             # remove arguments
35 0           my $elem = $module_name_token->next_sibling;
36 0           while ($elem->content ne ';') {
37 0           my $next = $elem->next_sibling;
38 0           $elem->remove;
39 0           $elem = $next;
40             }
41              
42             # add ()
43 0           $module_name_token->insert_after(PPI::Token::Structure->new(')'));
44 0           $module_name_token->insert_after(PPI::Token::Structure->new('('));
45 0           $module_name_token->insert_after(PPI::Token::Whitespace->new(' '));
46             }
47             }
48              
49             1;