line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::MigrateToTest2V0::Rule::ReplaceUseTestMoreToUseTest2V0; |
2
|
1
|
|
|
1
|
|
1151
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use parent 'App::MigrateToTest2V0::Rule'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub apply { |
7
|
0
|
|
|
0
|
0
|
|
my ($class, $doc) = @_; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $use = $doc->find_first(sub { |
10
|
0
|
|
|
0
|
|
|
my (undef, $elem) = @_; |
11
|
0
|
|
0
|
|
|
|
return $elem->isa('PPI::Statement::Include') && $elem->module eq 'Test::More'; |
12
|
0
|
|
|
|
|
|
}); |
13
|
0
|
0
|
|
|
|
|
return unless $use; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $module_name_token = $use->schild(1); |
16
|
0
|
|
|
|
|
|
$module_name_token->set_content('Test2::V0'); |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
return unless $use->arguments; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $arg_kind = ($use->arguments)[0]; |
21
|
|
|
|
|
|
|
# add statement |
22
|
0
|
0
|
|
|
|
|
if ($arg_kind eq 'tests') { |
|
|
0
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# plan tests => ...; |
24
|
0
|
|
|
|
|
|
my $test_num = ($use->arguments)[2]; |
25
|
0
|
|
|
|
|
|
my $plan_stmt = PPI::Statement->new; |
26
|
0
|
|
|
|
|
|
$plan_stmt->add_element(PPI::Token::Whitespace->new("\n")); |
27
|
0
|
|
|
|
|
|
$plan_stmt->add_element(PPI::Token::Word->new('plan')); |
28
|
0
|
|
|
|
|
|
$plan_stmt->add_element(PPI::Token::Whitespace->new(' ')); |
29
|
0
|
|
|
|
|
|
$plan_stmt->add_element(PPI::Token::Word->new('tests')); |
30
|
0
|
|
|
|
|
|
$plan_stmt->add_element(PPI::Token::Whitespace->new(' ')); |
31
|
0
|
|
|
|
|
|
$plan_stmt->add_element(PPI::Token::Operator->new('=>')); |
32
|
0
|
|
|
|
|
|
$plan_stmt->add_element(PPI::Token::Whitespace->new(' ')); |
33
|
0
|
|
|
|
|
|
$plan_stmt->add_element(PPI::Token::Number->new($test_num)); |
34
|
0
|
|
|
|
|
|
$plan_stmt->add_element(PPI::Token::Structure->new(';')); |
35
|
0
|
|
|
|
|
|
$use->insert_after($plan_stmt); |
36
|
|
|
|
|
|
|
} elsif ($arg_kind eq 'skip_all') { |
37
|
|
|
|
|
|
|
# skip_all ...; |
38
|
0
|
|
|
|
|
|
my $skip_reason = ($use->arguments)[2]; |
39
|
0
|
|
|
|
|
|
my $skip_all_stmt = PPI::Statement->new; |
40
|
0
|
|
|
|
|
|
$skip_all_stmt->add_element(PPI::Token::Whitespace->new("\n")); |
41
|
0
|
|
|
|
|
|
$skip_all_stmt->add_element(PPI::Token::Word->new('skip_all')); |
42
|
0
|
|
|
|
|
|
$skip_all_stmt->add_element(PPI::Token::Whitespace->new(' ')); |
43
|
0
|
|
|
|
|
|
$skip_all_stmt->add_element($skip_reason); |
44
|
0
|
|
|
|
|
|
$skip_all_stmt->add_element(PPI::Token::Structure->new(';')); |
45
|
0
|
|
|
|
|
|
$use->insert_after($skip_all_stmt); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# remove arguments |
49
|
0
|
|
|
|
|
|
my $elem = $module_name_token->next_sibling; |
50
|
0
|
|
|
|
|
|
while ($elem->content ne ';') { |
51
|
0
|
|
|
|
|
|
my $next = $elem->next_sibling; |
52
|
0
|
|
|
|
|
|
$elem->remove; |
53
|
0
|
|
|
|
|
|
$elem = $next; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |