blib/lib/Pod/Weaver/Plugin/Sort/Sub.pm

filter: Statementstmt 26.0% 18 / 69 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 24.7% 22 / 89 CC 9 SCAR 40.2
CC
9
Cov
22%
weave_section
79.7
BEGIN
1.0
BEGIN
1.0
CRAP 55.5
↑ Summary
1 package Pod::Weaver::Plugin::Sort::Sub;
2  
3 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 1 our $DATE = '2019-12-17'; # DATE
5 1 our $DIST = 'Pod-Weaver-Plugin-Sort-Sub'; # DIST
6 1 our $VERSION = '0.005'; # VERSION
7  
8 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 with 'Pod::Weaver::Role::AddTextToSection';
11 1 with 'Pod::Weaver::Role::Section';
12  
13 1 ▶use Data::Sah qw(normalize_schema);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 #use Data::Sah::Util::Type qw(get_type);
15  
16 0 ▶sub weave_section {
Subroutine weave_section: not called CC=9 SCAR=43.8
Pod undocumented
17 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 my ($self, $document, $input) = @_;
20  
21 0 my $filename = $input->{filename};
22  
23 0 my $package;
24 0 ▶ if ($filename =~ m!^lib/(.+)\.pm$!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ m[^lib/(.+)\.pm$]) 0 0 0
25 0 $package = $1;
26 0 $package =~ s!/!::!g;
27  
28 0 my $package_pm = $package;
29 0 $package_pm =~ s!::!/!g;
30 0 $package_pm .= ".pm";
31  
32 0 ▶ if ($package =~ /^Sort::Sub::([a-z_0-9][^:]*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /^Sort::Sub::([a-z_0-9][^:]*)/) 0 0 0
33 0 my $routine = $1;
34  
35 0 my $meta = {};
36 {
37 0 local @INC = ("lib", @INC);
38 0 require $package_pm;
39 0 eval { $meta = $package->meta };
40 }
41  
42 # add POD section: SYNOPSIS
43 {
44 0 my @pod;
45  
46 0 push @pod, (
47 "Generate sorter (accessed as variable) via L<Sort::Sub> import:\n\n",
48  
49 " use Sort::Sub '\$$routine'; # use '\$$routine<i>' for case-insensitive sorting, '\$$routine<r>' for reverse sorting\n",
50 " my \@sorted = sort \$$routine ('item', ...);\n\n",
51  
52 "Generate sorter (accessed as subroutine):\n\n",
53  
54 " use Sort::Sub '$routine<ir>';\n",
55 " my \@sorted = sort {$routine} ('item', ...);\n\n",
56  
57 "Generate directly without Sort::Sub:\n\n",
58  
59 " use $package;\n",
60 " my \$sorter = $package\::gen_sorter(\n",
61 " ci => 1, # default 0, set 1 to sort case-insensitively\n",
62 " reverse => 1, # default 0, set 1 to sort in reverse order\n",
63 " );\n",
64 " my \@sorted = sort \$sorter ('item', ...);\n\n",
65  
66 "Use in shell/CLI with L<sortsub> (from L<App::sortsub>):\n\n",
67  
68 " % some-cmd | sortsub $routine\n",
69 " % some-cmd | sortsub $routine --ignore-case -r\n\n",
70  
71 );
72 0 $self->add_text_to_section(
73 $document, join("", @pod), "SYNOPSIS",
74 {ignore => 1},
75 );
76 }
77  
78 # add text to Description
79 {
80 0 my @pod;
81  
82 0 push @pod, (
83 "This module can generate sort subroutine. It is meant to be used via L<Sort::Sub>, although you can also use it directly via C<gen_sorter()>.\n\n",
84 );
85 0 $self->add_text_to_section(
86 $document, join("", @pod), "DESCRIPTION",
87 {ignore => 1},
88 );
89 }
90  
91 # create POD section: SORT ARGUMENTS
92 {
93 0 ▶ last unless $meta->{args};
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->{"args"} 0 0 0
94 0 my @pod;
95  
96 0 push @pod, "C<*> marks required arguments.\n\n";
97  
98 0 for my $argname (sort keys %{ $meta->{args} }) {
99 0 my $argspec = $meta->{args}{$argname};
100  
101 0 ▶ die "Argument '$argname' does not have schema" unless defined $argspec->{schema};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $argspec->{"schema"} 0 0 0
102 0 my $sch = normalize_schema($argspec->{schema});
103  
104 0 ▶ push @pod, "=head2 $argname", ($argspec->{req} ? "*":""), "\n\n";
Branch: 1 branch
BranchTrueFalseTotal
$argspec->{'req'} ? : 0 0 0
105  
106 0 push @pod, "$sch->[0].\n\n";
107  
108 0 ▶ if (defined $argspec->{summary}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argspec->{"summary"}) 0 0 0
109 0 require String::PodQuote;
110 0 push @pod, String::PodQuote::pod_quote($argspec->{summary}), ".\n\n";
111 }
112  
113 0 ▶ if ($argspec->{description}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($argspec->{"description"}) 0 0 0
114 0 require Markdown::To::POD;
115 0 my $pod = Markdown::To::POD::markdown_to_pod($argspec->{description});
116 # make sure we add a couple of blank lines in the end
117 0 $pod =~ s/\s+\z//s;
118 0 $pod .= "\n\n\n";
119 0 push @pod, $pod;
120 }
121 }
122  
123 $self->add_text_to_section(
124 0 $document, join("", @pod), "SORT ARGUMENTS",
125 {ignore => 1},
126 );
127 }
128  
129 # add modules to See Also
130 {
131 0 my @pod;
132  
133 0 push @pod, (
134 "L<Sort::Sub>\n\n",
135 );
136 0 $self->add_text_to_section(
137 $document, join("", @pod), "SEE ALSO",
138 {ignore => 1},
139 );
140 }
141  
142 0 $self->log(["Generated POD for '%s'", $filename]);
143  
144 } # Sah::Schema::*
145 }
146 }
147  
148 1 1;
149 # ABSTRACT: Plugin to use when building Sort::Sub::* modules
150  
151 __END__
↑ Summary