File Coverage

blib/lib/PPIx/Regexp/Structure/CharClass.pm
Criterion Covered Total %
statement 27 30 90.0
branch 5 8 62.5
condition 2 3 66.6
subroutine 9 10 90.0
pod 2 2 100.0
total 45 53 84.9


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             PPIx::Regexp::Structure::CharClass - Represent a character class
4              
5             =head1 SYNOPSIS
6              
7             use PPIx::Regexp::Dumper;
8             PPIx::Regexp::Dumper->new( 'qr{[fo]}smx' )
9             ->print();
10              
11             =head1 INHERITANCE
12              
13             C<PPIx::Regexp::Structure::CharClass> is a
14             L<PPIx::Regexp::Structure|PPIx::Regexp::Structure>.
15              
16             C<PPIx::Regexp::Structure::CharClass> has no descendants.
17              
18             =head1 DESCRIPTION
19              
20             This class represents a square-bracketed character class.
21              
22             =head1 METHODS
23              
24             This class provides the following public methods. Methods not documented
25             here are private, and unsupported in the sense that the author reserves
26             the right to change or remove them without notice.
27              
28             =cut
29              
30             package PPIx::Regexp::Structure::CharClass;
31              
32 9     9   45 use strict;
  9         13  
  9         252  
33 9     9   33 use warnings;
  9         11  
  9         375  
34              
35 9     9   34 use base qw{ PPIx::Regexp::Structure };
  9         12  
  9         683  
36              
37 9         732 use PPIx::Regexp::Constant qw{
38             LITERAL_LEFT_CURLY_REMOVED_PHASE_2
39             @CARP_NOT
40 9     9   39 };
  9         11  
41 9     9   52 use PPIx::Regexp::Util qw{ :width_one __instance };
  9         12  
  9         2787  
42              
43             our $VERSION = '0.091';
44              
45             sub __new {
46 37     37   118 my ( $class, @args ) = @_;
47 37 50       108 ref $class and $class = ref $class;
48 37         64 my %brkt;
49 37         99 $brkt{finish} = pop @args;
50 37         87 $brkt{start} = shift @args;
51             __instance( $args[0], 'PPIx::Regexp::Token::Operator' )
52             and $args[0]->content() eq '^'
53 37 100 66     126 and $brkt{type} = shift @args;
54 37         218 return $class->SUPER::__new( \%brkt, @args );
55             }
56              
57             sub explain {
58 0     0 1 0 my ( $self ) = @_;
59 0 0       0 $self->negated()
60             and return 'Inverted character class';
61 0         0 return 'Character class';
62             }
63              
64             =head2 negated
65              
66             $class->negated() and print "Class is negated\n";
67              
68             This method returns true if the character class is negated -- that is,
69             if the first token inside the left square bracket is a caret (C<^>).
70              
71             =cut
72              
73             sub negated {
74 2     2 1 6 my ( $self ) = @_;
75 2 100       10 return $self->type() ? 1 : 0;
76             }
77              
78             sub __following_literal_left_curly_disallowed_in {
79 1     1   4 return LITERAL_LEFT_CURLY_REMOVED_PHASE_2;
80             }
81              
82             # Called by the lexer to record the capture number.
83             sub __PPIX_LEXER__record_capture_number {
84 36     36   99 my ( undef, $number ) = @_; # Invocant unused
85 36         67 return $number;
86             }
87              
88             1;
89              
90             __END__
91              
92             =head1 SUPPORT
93              
94             Support is by the author. Please file bug reports at
95             L<https://rt.cpan.org/Public/Dist/Display.html?Name=PPIx-Regexp>,
96             L<https://github.com/trwyant/perl-PPIx-Regexp/issues>, or in
97             electronic mail to the author.
98              
99             =head1 AUTHOR
100              
101             Thomas R. Wyant, III F<wyant at cpan dot org>
102              
103             =head1 COPYRIGHT AND LICENSE
104              
105             Copyright (C) 2009-2023, 2025 by Thomas R. Wyant, III
106              
107             This program is free software; you can redistribute it and/or modify it
108             under the same terms as Perl 5.10.0. For more details, see the full text
109             of the licenses in the directory LICENSES.
110              
111             This program is distributed in the hope that it will be useful, but
112             without any warranty; without even the implied warranty of
113             merchantability or fitness for a particular purpose.
114              
115             =cut
116              
117             # ex: set textwidth=72 :