File Coverage

blib/lib/PPIx/Regexp/Structure/Code.pm
Criterion Covered Total %
statement 21 23 91.3
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 29 32 90.6


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             PPIx::Regexp::Structure::Code - Represent one of the code structures.
4              
5             =head1 SYNOPSIS
6              
7             use PPIx::Regexp::Dumper;
8             PPIx::Regexp::Dumper->new( 'qr{(?{print "hello sailor\n")}smx' )
9             ->print();
10              
11             =head1 INHERITANCE
12              
13             C is a
14             L.
15              
16             C has no descendants.
17              
18             =head1 DESCRIPTION
19              
20             This class represents one of the code structures, either
21              
22             (?{ code })
23              
24             or
25              
26             (??{ code })
27              
28             =head1 METHODS
29              
30             This class provides no public methods beyond those provided by its
31             superclass.
32              
33             =cut
34              
35             package PPIx::Regexp::Structure::Code;
36              
37 9     9   75 use strict;
  9         20  
  9         268  
38 9     9   45 use warnings;
  9         21  
  9         253  
39              
40 9     9   46 use base qw{ PPIx::Regexp::Structure };
  9         19  
  9         839  
41              
42 9     9   66 use PPIx::Regexp::Constant qw{ @CARP_NOT };
  9         29  
  9         2087  
43              
44             our $VERSION = '0.087';
45              
46             # The only child of this structure should be a single
47             # PPIx::Regexp::Token::Code. Anything else gets turned into the
48             # appropriate ::Unknown object.
49             sub __PPIX_LEXER__finalize {
50 9     9   32 my ( $self ) = @_; # $lexer unused
51              
52 9         20 my $count;
53 9         21 my $errors = 0;
54              
55 9         46 foreach my $kid ( $self->children() ) {
56              
57 10 100       49 if ( $kid->isa( 'PPIx::Regexp::Token::Code' ) ) {
58 9 50       60 $count++
59             or next;
60 0         0 $errors++;
61 0         0 $kid->__error(
62             'Code structure can contain only one code token' );
63             } else {
64              
65 1         5 $errors++;
66              
67 1         24 $kid->__error(
68             'Code structure may not contain a ' . ref $kid );
69             }
70              
71             }
72 9         29 return $errors;
73             }
74              
75             1;
76              
77             __END__