| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use Applify; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use File::Find; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use if -e '.ship.conf', lib => 'lib'; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | option bool => i => 'Replace source', 0; | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | option bool => recursive => 'Recurse into directories in source list', | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 0, (alias => 'r'); | ||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | option str => eopm => 'End of perl module marker', '^1;'; | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | documentation 'App::podify'; | |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub check_pod { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_pod: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | for my $section (qw(attrs subs)) { | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | for my $name (keys %{$self->{$section} || {}}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{$section} || {}
MC/DC0%0/1
$self->{$section} || {}
$self->{$section}
Truth table0%0/2
A
A= $self->{$section}
| |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | warn "Missing $section in pod: $name\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | sub find_files { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_files: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | my ($self, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | my @files; | |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | File::Find::find( | ||||||||||||||||||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 34 | no_chdir => 1, | ||||||||||||||||||||||||||||||||||||||||||||
| 35 | 19 | ▶ | wanted => sub { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 19 | ▶ | $File::Find::prune = 1 if -d $File::Find::name and !$self->recursive; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-d $File::Find::name and not $self->recursive
MC/DC100%2/2
-d $File::Find::name and not $self->recursive
-d $File::Find::name
not $self->recursive
Truth table100%3/3
A and not(B)
A= -d $File::Find::nameB= not $self->recursive
| |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 19 | ▶ | $File::Find::prune = 0 if $File::Find::name eq $path; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 19 | ▶ | return if $File::Find::prune; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 18 | ▶ | push @files, $File::Find::name if $File::Find::name =~ m/[.] pm \z/msx; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | $path | |||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | return sort { length $a <=> length $b } @files; | |||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | sub generate { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=8 SCAR=21.6
| |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | my ($self, $OUT) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | $self->{pod} = $self->pod_template unless @{$self->{pod}}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | ▶ | if ($self->i) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | open $OUT, '>', $self->{perl_module} or die "Write $self->{perl_module}: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 56 | elsif (!$OUT) { | ||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $OUT = \*STDOUT; | |||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | my $code = join '', @{$self->{code}}; | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | $code =~ s!\n\n\n!\n\n!g; | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | $code =~ s!\n+use!\nuse!s; | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | $code =~ s!\n+$!\n\n!; | |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | print $OUT "${code}1;\n\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | ▶ | print $OUT "=encoding utf8\n\n" unless $self->{pod_has_encoding}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | print $OUT $_ for grep { !/^=cut/ } @{$self->{pod}}; | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | print $OUT "=cut\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | print $OUT "\n" . join '', @{$self->{data}} if @{$self->{data}}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | $self->{$_} = [] for qw(code data pod); | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | $self->{$_} = {} for qw(attrs subs); | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | $self; | |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=17 SCAR=28.6
| |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | my $eopm = $self->eopm; | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | my %has; | |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | open my $IN, '<', $self->{perl_module} or die "Read $self->{perl_module}: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | $eopm = qr{$eopm}; | |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | ▶ | while (<$IN>) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 106 | my $pod; | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 106 | ▶ | next if /^=encoding\s/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 105 | ▶ | $self->{attrs}{$1} = $1 if /^has\s+([a-z]\w*)/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 105 | ▶ | $self->{subs}{$1} = $1 if /^sub\s+([a-z]\w*)/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 105 | ▶ | $self->{documented}{$1} = $1 if /^=head2\s([a-z]\w*)/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 105 | ▶ | $self->{module_name} ||= $1 if /^package\s+([^\s;]+)/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"module_name"} ||= $1
MC/DC0%0/2
$self->{"module_name"} ||= $1
$self->{"module_name"}
$1
Truth table33%1/3
A ||= B
A= $self->{"module_name"}B= $1
| |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 105 | ▶ | $self->{module_version} ||= $1 if /^VERSION.*([\d\.]+)/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"module_version"} ||= $1
MC/DC0%0/2
$self->{"module_version"} ||= $1
$self->{"module_version"}
$1
Truth table0%0/3
A ||= B
A= $self->{"module_version"}B= $1
| |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 105 | ▶ | $pod = push @{$self->{pod}}, $_ if /^=head/ .. /=cut/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 105 | ▶ | push @{$self->{data}}, $_ if @{$self->{data}} or /^__DATA__$/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$self->{"data"};} or /^__DATA__$/
MC/DC100%2/2
@{$self->{"data"};} or /^__DATA__$/
@{$self->{"data"};}
/^__DATA__$/
Truth table100%3/3
A or B
A= @{$self->{"data"};}B= /^__DATA__$/
| |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 105 | ▶ | push @{$self->{code}}, $_ unless @{$self->{data}} or $pod or $_ =~ $eopm; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@{$self->{"data"};} or $pod or $_ =~ /$eopm/
@{$self->{"data"};} or $pod
MC/DC100%3/3
@{$self->{"data"};} or $pod or $_ =~ /$eopm/
@{$self->{"data"};}
$pod
$_ =~ /$eopm/
Truth table100%4/4
A or B or C
A= @{$self->{"data"};}B= $podC= $_ =~ /$eopm/
| |||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | sub pod_template { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pod_template: called CC=7 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | return [ | ||||||||||||||||||||||||||||||||||||||||||||
| 107 | sprintf("=head1 NAME\n\n%s - TODO\n\n", $self->{module_name} || 'Unknown'), | ||||||||||||||||||||||||||||||||||||||||||||
| 108 | $self->{module_version} ? printf("=head1 VERSION\n\n$%s\n\n", $self->{module_version}) : (), | ||||||||||||||||||||||||||||||||||||||||||||
| 109 | sprintf("=head1 SYNOPSIS\n\nTODO\n\n"), | ||||||||||||||||||||||||||||||||||||||||||||
| 110 | sprintf("=head1 DESCRIPTION\n\nTODO\n\n"), | ||||||||||||||||||||||||||||||||||||||||||||
| 111 | sprintf("=head1 ATTRIBUTES\n\n"), | ||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | map({ sprintf "=head2 %s\n\n", delete $self->{attrs}{$_} } sort keys %{$self->{attrs} || {}}), | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'attrs'} || {}
MC/DC0%0/1
$self->{'attrs'} || {}
$self->{'attrs'}
Truth table50%1/2
A
A= $self->{'attrs'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 113 | sprintf("=head1 METHODS\n\n"), | ||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | map({ sprintf "=head2 %s\n\n", delete $self->{subs}{$_} } sort keys %{$self->{subs} || {}}), | ||||||||||||||||||||||||||||||||||||||||||
|
Condition37%3/8
$self->{'subs'} || {}
$ENV{'PODIFY_AUTHOR'} || (getpwuid $<)[6] || (getpwuid $<)[0]
$ENV{"PODIFY_AUTHOR"} or (getpwuid $<)[6]
MC/DC0%0/1
$self->{'subs'} || {}
$self->{'subs'}
MC/DC0%0/3
$ENV{'PODIFY_AUTHOR'} || (getpwuid $<)[6] || (getpwuid $<)[0]
$ENV{"PODIFY_AUTHOR"}
(getpwuid $<)[6]
(getpwuid $<)[0]
Truth table50%1/2
A
A= $self->{'subs'}
Truth table25%1/4
A or B || C
A= $ENV{"PODIFY_AUTHOR"}B= (getpwuid $<)[6]C= (getpwuid $<)[0]
| |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | sprintf("=head1 AUTHOR\n\n%s\n\n", $ENV{PODIFY_AUTHOR} || (getpwuid $<)[6] || (getpwuid $<)[0]), | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{'module_name'} || 'Unknown'
MC/DC0%0/1
$self->{'module_name'} || 'Unknown'
$self->{'module_name'}
Truth table50%1/2
A
A= $self->{'module_name'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 116 | sprintf("=head1 COPYRIGHT AND LICENSE\n\nTODO\n\n"), | ||||||||||||||||||||||||||||||||||||||||||||
| 117 | sprintf("=head1 SEE ALSO\n\nTODO\n\n"), | ||||||||||||||||||||||||||||||||||||||||||||
| 118 | ]; | ||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | ▶ | sub post_process { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post_process: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | ▶ | delete $self->{attrs}{$_} or delete $self->{subs}{$_} for keys %{$self->{documented}}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | app { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my ($self, @paths) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | unless (@paths) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | die $self->_script->print_help, "No input files specified.\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | while (my $path = File::Spec->canonpath(shift @paths)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if (-d $path) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | push @paths, $self->find_files($path); | |||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 137 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->init; | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $self->{perl_module} = $path; | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->parse; | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $self->post_process; | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $self->generate; | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $self->check_pod; | |||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||