Weaver/Role/StringFromComment.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 100% 46 / 46 CC 3 SCAR 4.4
CC
3
Cov
100%
__ANON__
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Weaver/Section/Legal.pm ↑ Summary Weaver/Config.pm »
1 package Pod::Weaver::Role::StringFromComment 4.022;
2 # ABSTRACT: Extract a string from a specially formatted comment
3  
4 9 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # BEGIN BOILERPLATE
7 9 ▶use v5.22.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶no feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
Subroutine BEGIN: called CC=1 SCAR=0.0
12 # END BOILERPLATE
13  
14 9 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #pod =head1 OVERVIEW
17 #pod
18 #pod This role assists L<Pod::Weaver sections|Pod::Weaver::Role::Section> by
19 #pod allowing them to pull strings from the source comments formatted like:
20 #pod
21 #pod # KEYNAME: Some string...
22 #pod
23 #pod This is probably the most familiar to people using lines like the following to
24 #pod allow the L<Name section|Pod::Weaver::Section::Name> to determine a module's
25 #pod abstract:
26 #pod
27 #pod # ABSTRACT: Provides the HypnoToad with mind-control powers
28 #pod
29 #pod It will extract these strings by inspecting the C<ppi_document> which
30 #pod must be given.
31 #pod
32 #pod =head1 PRIVATE METHODS
33 #pod
34 #pod This role supplies only methods meant to be used internally by its consumer.
35 #pod
36 #pod =head2 _extract_comment_content($ppi_doc, $key)
37 #pod
38 #pod Given a key, try to find a comment matching C<# $key:> in the C<$ppi_document>
39 #pod and return everything but the prefix.
40 #pod
41 #pod e.g., given a document with a comment in it of the form:
42 #pod
43 #pod # ABSTRACT: Yada yada...
44 #pod
45 #pod ...and this is called...
46 #pod
47 #pod $self->_extract_comment_content($ppi, 'ABSTRACT')
48 #pod
49 #pod ...it returns to us:
50 #pod
51 #pod Yada yada...
52 #pod
53 #pod =cut
54  
55 60 ▶sub _extract_comment_content {
Subroutine _extract_comment_content: called CC=1 SCAR=0.0
56 60 my ($self, $ppi_document, $key) = @_;
57  
58 60 my $regex = qr/^\s*#+\s*$key:\s*(.+)$/m;
59  
60 60 my $content;
61 745 ▶ my $finder = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
62 745 my $node = $_[1];
63 745 ▶ return 0 unless $node->isa('PPI::Token::Comment');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isa("PPI::Token::Comment") 681 64 745
64 64 ▶ if ( $node->content =~ $regex ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->content =~ /$regex/u) 33 31 64
65 33 $content = $1;
66 33 return 1;
67 }
68 31 return 0;
69 60 };
70  
71 60 $ppi_document->find_first($finder);
72  
73 60 return $content;
74 }
75  
76 9 1;
77  
78 __END__
« Weaver/Section/Legal.pm ↑ Summary Weaver/Config.pm »