Elemental/Selectors.pm

filter: Statementstmt 100% 34 / 34 Branchbran 85.7% 12 / 14 Conditioncond 75.0% 9 / 12 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 90.5% 77 / 85 CC 12 SCAR 8.9
CC
12
Cov
92%
__ANON__
5.0
s_node
2.0
__ANON__
2.0
CRAP 2.4
« Elemental/Node.pm ↑ Summary Elemental/Command.pm »
1 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Pod::Elemental::Selectors 0.103006;
4 # ABSTRACT: predicates for selecting elements
5  
6 #pod =head1 OVERVIEW
7 #pod
8 #pod Pod::Elemental::Selectors provides a number of routines to check for
9 #pod Pod::Elemental paragraphs with given qualities.
10 #pod
11 #pod =head1 SELECTORS
12 #pod
13 #pod Selectors are predicates: they examine paragraphs and return either true or
14 #pod false. All the selectors have (by default) names like: C<s_whatever>. They
15 #pod expect zero or more parameters to affect the selection. If these parameters
16 #pod are given, but no paragraph, a callback will be returned that will expect a
17 #pod paragraph. If a paragraph is given, the selector will return immediately.
18 #pod
19 #pod For example, the C<s_command> selector expects a parameter that can be the name
20 #pod of the command desired. Both of the following uses are valid:
21 #pod
22 #pod # create and use a callback:
23 #pod
24 #pod my $selector = s_command('head1');
25 #pod my @headers = grep { $selector->($_) } @paragraphs;
26 #pod
27 #pod # just check a paragraph right now:
28 #pod
29 #pod if ( s_command('head1', $paragraph) ) { ... }
30 #pod
31 #pod The selectors can be imported individually or as the C<-all> group, and can be
32 #pod renamed with L<Sub::Exporter> features. (Selectors cannot I<yet> be curried by
33 #pod Sub::Exporter.)
34 #pod
35 #pod =cut
36  
37 12 ▶use List::Util 1.33 'any';
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 12 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
40 exports => [ qw(s_blank s_flat s_node s_command) ],
41 12 };
42  
43 #pod =head2 s_blank
44 #pod
45 #pod my $callback = s_blank;
46 #pod
47 #pod if( s_blank($para) ) { ... }
48 #pod
49 #pod C<s_blank> tests whether a paragraph is a Generic::Blank element.
50 #pod
51 #pod =cut
52  
53 267 ▶sub s_blank {
Subroutine s_blank: called CC=2 SCAR=7.0
Pod documented
54 267 ▶ my $code = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
55 267 my $para = shift;
56 267 ▶ return $para && $para->isa('Pod::Elemental::Element::Generic::Blank');
Condition100%3/3
$para && $para->isa('Pod::Elemental::Element::Generic::Blank')
!ll&&!rl&&r
1128138
MC/DC100%2/2
$para && $para->isa('Pod::Elemental::Element::Generic::Blank')
$para $para->isa('Pod::Elemental::Element::Generic::Blank')
Truth table100%3/3
A && B
A= $paraB= $para->isa('Pod::Elemental::Element::Generic::Blank')
ABresult
0X0
100
111
57 267 };
58  
59 267 ▶ return @_ ? $code->(@_) : $code;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 267 0 267
60 }
61  
62 #pod =head2 s_flat
63 #pod
64 #pod my $callback = s_flat;
65 #pod
66 #pod if( s_flat($para) ) { ... }
67 #pod
68 #pod C<s_flat> tests whether a paragraph does Pod::Elemental::Flat -- in other
69 #pod words, is content-only.
70 #pod
71 #pod =cut
72  
73 4 ▶sub s_flat {
Subroutine s_flat: called CC=2 SCAR=7.0
Pod documented
74 27 ▶ my $code = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
75 27 my $para = shift;
76 27 ▶ return $para && $para->does('Pod::Elemental::Flat');
Condition66%2/3
$para && $para->does('Pod::Elemental::Flat')
!ll&&!rl&&r
0198
MC/DC50%1/2
$para && $para->does('Pod::Elemental::Flat')
$para $para->does('Pod::Elemental::Flat')
Truth table66%2/3
A && B
A= $paraB= $para->does('Pod::Elemental::Flat')
ABresult
0X0
100
111
77 4 };
78  
79 4 ▶ return @_ ? $code->(@_) : $code;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 2 4
80 }
81  
82 #pod =head2 s_node
83 #pod
84 #pod my $callback = s_node;
85 #pod
86 #pod if( s_node($para) ) { ... }
87 #pod
88 #pod C<s_node> tests whether a paragraph does Pod::Elemental::Node -- in other
89 #pod words, whether it may have children.
90 #pod
91 #pod =cut
92  
93 12 ▶sub s_node {
Subroutine s_node: called CC=2 SCAR=7.1
Pod documented
94 12 ▶ my $code = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
95 12 my $para = shift;
96 12 ▶ return $para && $para->does('Pod::Elemental::Node');
Condition66%2/3
$para && $para->does('Pod::Elemental::Node')
!ll&&!rl&&r
066
MC/DC50%1/2
$para && $para->does('Pod::Elemental::Node')
$para $para->does('Pod::Elemental::Node')
Truth table66%2/3
A && B
A= $paraB= $para->does('Pod::Elemental::Node')
ABresult
0X0
100
111
97 12 };
98  
99 12 ▶ return @_ ? $code->(@_) : $code;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 12 0 12
100 }
101  
102 #pod =head2 s_command
103 #pod
104 #pod my $callback = s_command;
105 #pod my $callback = s_command( $command_name);
106 #pod my $callback = s_command(\@command_names);
107 #pod
108 #pod if( s_command(undef, \$para) ) { ... }
109 #pod
110 #pod if( s_command( $command_name, \$para) ) { ... }
111 #pod if( s_command(\@command_names, \$para) ) { ... }
112 #pod
113 #pod C<s_command> tests whether a paragraph does Pod::Elemental::Command. If a
114 #pod command name (or a reference to an array of command names) is given, the tested
115 #pod paragraph's command must match one of the given command names.
116 #pod
117 #pod =cut
118  
119 471 ▶sub s_command {
Subroutine s_command: called CC=2 SCAR=6.9
Pod documented
120 471 my $command = shift;
121  
122 693 ▶ my $code = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
123 693 my $para = shift;
124 693 ▶ return unless $para && $para->does('Pod::Elemental::Command');
Branch: 1 branch
BranchTrueFalseTotal
unless $para and $para->does("Pod::Elemental::Command") 444 249 693
Condition66%2/3
$para and $para->does("Pod::Elemental::Command")
!ll&&!rl&&r
0444249
MC/DC50%1/2
$para and $para->does("Pod::Elemental::Command")
$para $para->does("Pod::Elemental::Command")
Truth table66%2/3
A and B
A= $paraB= $para->does("Pod::Elemental::Command")
ABresult
0X0
100
111
125 249 ▶ return 1 unless defined $command;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $command 10 239 249
126  
127 239 ▶ my $alts = ref $command ? $command : [ $command ];
Branch: 1 branch
BranchTrueFalseTotal
ref $command ? : 227 12 239
128 239 ▶ return any { $para->command eq $_ } @$alts;
Subroutine __ANON__: called CC=1 SCAR=0.0
129 471 };
130  
131 471 ▶ return @_ ? $code->(@_) : $code;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 434 37 471
132 }
133  
134 12 1;
135  
136 __END__
« Elemental/Node.pm ↑ Summary Elemental/Command.pm »