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<PPIx::Regexp::Structure::Code> is a
14             L<PPIx::Regexp::Structure|PPIx::Regexp::Structure>.
15              
16             C<PPIx::Regexp::Structure::Code> 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   41 use strict;
  9         10  
  9         250  
38 9     9   37 use warnings;
  9         10  
  9         337  
39              
40 9     9   52 use base qw{ PPIx::Regexp::Structure };
  9         11  
  9         687  
41              
42 9     9   35 use PPIx::Regexp::Constant qw{ @CARP_NOT };
  9         11  
  9         1883  
43              
44             our $VERSION = '0.091';
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   20 my ( $self ) = @_; # $lexer unused
51              
52 9         10 my $count;
53 9         14 my $errors = 0;
54              
55 9         34 foreach my $kid ( $self->children() ) {
56              
57 10 100       35 if ( $kid->isa( 'PPIx::Regexp::Token::Code' ) ) {
58 9 50       46 $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         2 $errors++;
66              
67 1         17 $kid->__error(
68             'Code structure may not contain a ' . ref $kid );
69             }
70              
71             }
72 9         19 return $errors;
73             }
74              
75             1;
76              
77             __END__
78              
79             =head1 SUPPORT
80              
81             Support is by the author. Please file bug reports at
82             L<https://rt.cpan.org/Public/Dist/Display.html?Name=PPIx-Regexp>,
83             L<https://github.com/trwyant/perl-PPIx-Regexp/issues>, or in
84             electronic mail to the author.
85              
86             =head1 AUTHOR
87              
88             Thomas R. Wyant, III F<wyant at cpan dot org>
89              
90             =head1 COPYRIGHT AND LICENSE
91              
92             Copyright (C) 2009-2023, 2025 by Thomas R. Wyant, III
93              
94             This program is free software; you can redistribute it and/or modify it
95             under the same terms as Perl 5.10.0. For more details, see the full text
96             of the licenses in the directory LICENSES.
97              
98             This program is distributed in the hope that it will be useful, but
99             without any warranty; without even the implied warranty of
100             merchantability or fitness for a particular purpose.
101              
102             =cut
103              
104             # ex: set textwidth=72 :