script/ppix_editortools

filter: Statementstmt 94.4% 34 / 36 Branchbran 56.2% 9 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 84.4% 49 / 58 CC 3 SCAR 4.1
CC
3
Cov
83%
write_file
2.0
read_file
2.0
BEGIN
1.0
CRAP 1.5
« blib/lib/PPIx/EditorTools/ReturnObject.pm ↑ Summary
1 #!/usr/bin/perl
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5  
6 4 ▶use Getopt::Long qw(GetOptions);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Pod::Usage qw(pod2usage);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # This is a command line script to use the capabilities of this package
10 # with a temporary API and a temporary name!
11  
12 4 ▶pod2usage() if not @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 4 4
13 4 my %opt;
14 4 ▶GetOptions(\%opt,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%opt, "inplace", "RenameVariable", "line=i", "column=i", "replacement=s", "to-camel-case=s", "help") or pod2usage() 4 0 4
15 'inplace',
16 'RenameVariable',
17 'line=i',
18 'column=i',
19 'replacement=s',
20 'to-camel-case=s',
21  
22 'help',
23 ) or pod2usage();
24 4 ▶pod2usage() if $opt{help};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"help"} 0 4 4
25  
26 4 ▶if ($opt{RenameVariable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{'RenameVariable'}) { } 4 0 4
27 4 require PPIx::EditorTools::RenameVariable;
28 4 my $file = shift @ARGV;
29  
30 4 my $code = read_file($file);
31  
32 4 my %param;
33 4 ▶ if (exists $opt{replacement}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opt{'replacement'}) { } 3 1 4
elsif (exists $opt{'to-camel-case'}) { } 1 0 1
34 3 $param{replacement} = $opt{replacement};
35 } elsif (exists $opt{'to-camel-case'}) {
36 1 $param{'to_camel_case'} = $opt{'to-camel-case'};
37 } else {
38 0 die 'Need eiher replacement or to-camel-case';
39 }
40  
41  
42 my $result =
43 PPIx::EditorTools::RenameVariable->new->rename(
44 code => $code,
45 line => $opt{line},
46 column => $opt{column},
47 4 %param,
48 )->code;
49 ;
50 4 write_file($file, $result);
51 } else {
52 0 pod2usage();
53 }
54  
55 4 exit;
56  
57  
58 4 ▶sub read_file {
Subroutine read_file: called CC=2 SCAR=7.0
59 4 my ($file) = @_;
60 4 ▶ open my $in, '<', $file or die "Could not open file '$file' for reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $file or die "Could not open file '${file}' for reading: $!" 4 0 4
61 4 local $/ = undef;
62 4 return <$in>;
63 }
64  
65 4 ▶sub write_file {
Subroutine write_file: called CC=2 SCAR=7.1
66 4 my ($file, $data) = @_;
67 4 ▶ open my $out, '>', $file or die;
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $file or die 4 0 4
68 4 print $out $data;
69 }
70  
71  
72 =head1 NAME
73  
74 ppix_editortools - command line interface for the PPIx::EditorTools
75  
76 =head1 SYNOPSIS
77  
78 --RenameVariable --line 8 column 12 --replacement NEW_NAME --inplace
79  
80  
81 =cut
82  
« blib/lib/PPIx/EditorTools/ReturnObject.pm ↑ Summary