blib/lib/Dist/Zilla/Plugin/Sorter.pm

filter: Statementstmt 30.3% 20 / 66 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod n/a totaltotal 28.4% 27 / 95 CC 11 SCAR 31.5
CC
11
Cov
24%
munge_files
43.8
before_build
30.0
_get_meta
2.0
CRAP 23.3
↑ Summary
1 package Dist::Zilla::Plugin::Sorter;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict 'subs', 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 with (
13 #'Dist::Zilla::Role::RequireFromBuild', # not ready at before-build phase?
14 'Dist::Zilla::Role::BeforeBuild',
15 'Dist::Zilla::Role::FileMunger',
16 'Dist::Zilla::Role::FileFinderUser' => {
17 default_finders => [':InstallModules'],
18 },
19 );
20  
21 # AUTHOR
22 our $DATE = '2024-04-24'; # DATE
23 our $DIST = 'Dist-Zilla-Plugin-Sorter'; # DIST
24 our $VERSION = '0.001'; # VERSION
25  
26 0 ▶sub _get_meta {
Subroutine _get_meta: not called CC=1 SCAR=6.9
27 0 my ($self, $pkg) = @_;
28  
29 0 $self->require_from_build($pkg);
30 0 $pkg->meta;
31 }
32  
33 # dzil also wants to get abstract for main module to put in dist's
34 # META.{yml,json}
35 0 ▶sub before_build {
Subroutine before_build: not called CC=5 SCAR=34.0
36 0 my $self = shift;
37 0 my $name = $self->zilla->name;
38 0 my $class = $name; $class =~ s{ [\-] }{::}gmx;
39 0 ▶ my $filename = $self->zilla->_main_module_override ||
Condition0%0/3
$self->zilla->_main_module_override || catfile('lib', split(/ [\-] /mx, "$name.pm", 0))
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->zilla->_main_module_override || catfile('lib', split(/ [\-] /mx, "$name.pm", 0))
$self->zilla->_main_module_override catfile('lib', split(/ [\-] /mx, "$name.pm", 0))
Truth table0%0/3
A || B
A= $self->zilla->_main_module_overrideB= catfile('lib', split(/ [\-] /mx, "$name.pm", 0))
ABresult
1X1
011
000
40 catfile( 'lib', split m{ [\-] }mx, "${name}.pm" );
41  
42 0 ▶ $filename or die 'No main module specified';
Branch: 1 branch
BranchTrueFalseTotal
$filename or die "No main module specified" 0 0 0
43 0 ▶ -f $filename or die "Path ${filename} does not exist or not a file";
Branch: 1 branch
BranchTrueFalseTotal
-f $filename or die "Path $filename does not exist or not a file" 0 0 0
44 #open my $fh, '<', $filename or die "File ${filename} cannot open: $!";
45  
46 0 my ($meta, $abstract);
47 #$meta = $self->_get_meta($class);
48 {
49 0 local @INC = ("lib", @INC);
50 0 (my $mod = $name) =~ s/-/::/g;
51 0 (my $mod_pm = "$mod.pm") =~ s!::!/!g;
52 0 require $mod_pm;
53 0 $meta = $mod->meta;
54 }
55 0 $abstract = $meta->{summary};
56  
57 0 ▶ unless ($abstract) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($abstract) 0 0 0
58 0 $self->log_debug("meta does not contain summary, skipping setting Abstract from meta's summary");
59 0 return;
60 }
61  
62 0 $self->log("Setting Abstract from meta's summary: $abstract");
63 0 $self->zilla->abstract($abstract);
64 0 return;
65 }
66  
67 0 ▶sub munge_files {
Subroutine munge_files: not called CC=7 SCAR=37.8
68 1 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
69 0 my $self = shift;
70  
71 0 local @INC = ("lib", @INC);
72  
73 # gather dist modules
74 0 my %distmodules;
75 0 for my $file (@{ $self->found_files }) {
76 0 ▶ next unless $file->name =~ m!\Alib/(.+)\.pm\z!;
Branch: 1 branch
BranchTrueFalseTotal
unless $file->name =~ m[\Alib/(.+)\.pm\z] 0 0 0
77 0 my $mod = $1; $mod =~ s!/!::!g;
78 0 $distmodules{$mod}++;
79 }
80  
81 0 for my $file (@{ $self->found_files }) {
82 0 ▶ next unless $file->name =~ m!\Alib/(Sort/Sub/.+)\.pm\z!;
Branch: 1 branch
BranchTrueFalseTotal
unless $file->name =~ m[\Alib/(Sort/Sub/.+)\.pm\z] 0 0 0
83 0 (my $pkg = $1) =~ s!/!::!g;
84 0 my $meta = $self->_get_meta($pkg);
85  
86 # fill-in ABSTRACT from scenario's summary
87 {
88 0 my $content = $file->content;
89 0 my $abstract = $meta->{summary};
90 0 ▶ last unless $abstract;
Branch: 1 branch
BranchTrueFalseTotal
unless $abstract 0 0 0
91 0 ▶ $content =~ s{^#\s*ABSTRACT:.*}{# ABSTRACT: $abstract}m
Branch: 1 branch
BranchTrueFalseTotal
$content =~ s/^#\s*ABSTRACT:.*/# ABSTRACT: $abstract/m or die q[Can't insert abstract for ] . $file->name 0 0 0
92 or die "Can't insert abstract for " . $file->name;
93 0 $self->log(["inserting abstract for %s (%s)",
94 $file->name, $abstract]);
95  
96 0 $file->content($content);
97 }
98 } # foreach file
99 0 return;
100 }
101  
102 __PACKAGE__->meta->make_immutable;
103 1;
104 # ABSTRACT: Plugin to use when building Sorter::* distribution
105  
106 __END__
↑ Summary