| 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')
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')
| |||||||||||||||||||||||||||||
| 57 | 267 | }; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 267 | ▶ | return @_ ? $code->(@_) : $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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')
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')
| |||||||||||||||||||||||||||||
| 77 | 4 | }; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 4 | ▶ | return @_ ? $code->(@_) : $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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')
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')
| |||||||||||||||||||||||||||||
| 97 | 12 | }; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 12 | ▶ | return @_ ? $code->(@_) : $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$para and $para->does("Pod::Elemental::Command")
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")
| |||||||||||||||||||||||||||||
| 125 | 249 | ▶ | return 1 unless defined $command; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 239 | ▶ | my $alts = ref $command ? $command : [ $command ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 12 | 1; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | __END__ | ||||||||||||||||||||||||||||