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 is a
14             L.
15              
16             C 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   57 use strict;
  9         21  
  9         247  
33 9     9   45 use warnings;
  9         19  
  9         257  
34              
35 9     9   47 use base qw{ PPIx::Regexp::Structure };
  9         18  
  9         767  
36              
37 9         803 use PPIx::Regexp::Constant qw{
38             LITERAL_LEFT_CURLY_REMOVED_PHASE_2
39             @CARP_NOT
40 9     9   67 };
  9         20  
41 9     9   75 use PPIx::Regexp::Util qw{ :width_one __instance };
  9         14  
  9         3461  
42              
43             our $VERSION = '0.088';
44              
45             sub __new {
46 37     37   178 my ( $class, @args ) = @_;
47 37 50       126 ref $class and $class = ref $class;
48 37         74 my %brkt;
49 37         122 $brkt{finish} = pop @args;
50 37         125 $brkt{start} = shift @args;
51             __instance( $args[0], 'PPIx::Regexp::Token::Operator' )
52             and $args[0]->content() eq '^'
53 37 100 66     123 and $brkt{type} = shift @args;
54 37         292 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 5 my ( $self ) = @_;
75 2 100       11 return $self->type() ? 1 : 0;
76             }
77              
78             sub __following_literal_left_curly_disallowed_in {
79 1     1   7 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   131 my ( undef, $number ) = @_; # Invocant unused
85 36         103 return $number;
86             }
87              
88             1;
89              
90             __END__