Cats/Parser/MGC.pm

filter: Statementstmt 28.8% 13 / 45 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 44.4% 4 / 9 Podpod 100% 2 / 2 totaltotal 27.5% 19 / 69 CC 7 SCAR 19.2
CC
7
Cov
23%
new
12.0
__ANON__
12.0
__ANON__
6.0
CRAP 6.8
↑ Summary Cats.pm »
1 package Pod::Cats::Parser::MGC;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use parent qw(Parser::MGC);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.08';
9  
10 =head1 NAME
11  
12 Pod::Cats::Parser::MGC - Parser for C<< X<elements> >> in L<Pod::Cats>
13  
14 =head1 DESCRIPTION
15  
16 Entities in Pod::Cats can be demarcated by any set of delimiters, configured in
17 L<Pod::Cats/new>. That configuration ends up here.
18  
19 Given a string with entities so demarcated, recursively extracts the contents of
20 the entities and passes them to the Pod::Cats object for handling.
21  
22 Thus collates a sequence of (normal string, element, normal string), etc. The
23 exact contents of I<element> depends on what your Pod::Cats subclass does with
24 the contents of the element; but the contents of I<normal string> is just the
25 original text up to the first element.
26  
27 I<element> may, of course, be another sequence of the above, because it's
28 pseudo-recursive (actually it just trundles along iteratively, maintaining a
29 nesting level and an expectation of ending delimiters).
30  
31 =head1 METHODS
32  
33 =head2 new
34  
35 Constructs a new parser object. Accepts a hash of C<obj> and C<delimiters>.
36  
37 C<obj> is required and must contain a Pod::Cats subclass; C<delimiters> defaults
38 to C<< "<" >>, like normal POD.
39  
40 See L<Pod::Cats/new> for delimiters.
41  
42 =cut
43  
44 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
45 0 my $self = shift->SUPER::new(@_);
46 0 my %o = @_;
47 0 ▶ $self->{obj} = $o{object} or die "Expected argument 'object'";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"obj"} = $o{"object"} or die "Expected argument 'object'" 0 0 0
48 0 ▶ $self->{delimiters} = $o{delimiters} || "<";
Condition0%0/2
$o{'delimiters'} || '<'
l!l
00
MC/DC0%0/1
$o{'delimiters'} || '<'
$o{'delimiters'}
Truth table0%0/2
A
A= $o{'delimiters'}
Aresult
11
00
49  
50 0 return $self;
51 }
52  
53 =head2 parse
54  
55 See L<Parser::MGC> for how parse works. This just finds entities based on the
56 configured delimiters, and fires events to the object provided to L</new>.
57  
58 =cut
59  
60 0 ▶sub parse {
Subroutine parse: not called CC=1 SCAR=6.9
Pod documented
61 0 my $self = shift;
62 0 my $pod_cats = $self->{obj};
63  
64 # Can't grab the whole lot with one re (yet) so I will grab one and expect
65 # more.
66  
67 0 ▶ my $ret = $self->sequence_of(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
68 0 my $odre;
69 0 ▶ if ($self->scope_level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->scope_level) { } 0 0 0
70 0 $odre = qr/\Q$self->{delimiters}/;
71 }
72 else {
73 0 $odre = qr/[\Q$self->{delimiters}\E]/;
74 }
75  
76 $self->any_of(
77 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
78 # After we're in 1 level we've committed to an exact delimiter.
79 0 my $tag = $self->expect( qr/[A-Z](?=$odre)/ );
80  
81 0 $self->commit;
82  
83 0 my $odel;
84
85 0 ▶ if ($self->scope_level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->scope_level) { } 0 0 0
86 0 $odel = $self->expect( $self->{delimiters} );
87 }
88 else {
89 0 $odel = $self->expect( $odre );
90 0 $odel .= $self->expect( qr/\Q$odel\E*/ );
91 }
92  
93 0 (my $cdel = $odel) =~ tr/<({[/>)}]/;
94  
95 # The opening delimiter is the same char repeated, never
96 # different ones.
97 0 local $self->{delimiters} = $odel;
98  
99 0 ▶ if ($tag eq 'Z') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "Z") 0 0 0
100 0 $self->expect( $cdel );
101 0 $self->{level}--;
102 0 return;
103 }
104  
105 my $retval = $pod_cats->handle_entity(
106 $tag => @{
107 0 $self->scope_of( undef, \&parse, $cdel )
108 }
109 );
110 0 return $retval;
111 },
112  
113 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
114 0 ▶ if ($self->scope_level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->scope_level) { } 0 0 0
115 0 return $self->substring_before( qr/[A-Z]\Q$self->{delimiters}/ );
116 }
117 else {
118 0 return $self->substring_before( qr/[A-Z]$odre/ );
119 }
120 },
121 )
122 0 });
123 }
124  
125 1 1;
↑ Summary Cats.pm »