File Coverage

blib/lib/PPIx/Regexp/Token/Unknown.pm
Criterion Covered Total %
statement 28 32 87.5
branch 3 6 50.0
condition n/a
subroutine 10 13 76.9
pod 5 5 100.0
total 46 56 82.1


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             PPIx::Regexp::Token::Unknown - Represent an unknown token
4              
5             =head1 SYNOPSIS
6              
7             use PPIx::Regexp::Dumper;
8             PPIx::Regexp::Dumper->new( 'xyzzy' )
9             ->print();
10              
11             =head1 INHERITANCE
12              
13             C<PPIx::Regexp::Token::Unknown> is a
14             L<PPIx::Regexp::Token|PPIx::Regexp::Token>.
15              
16             C<PPIx::Regexp::Token::Unknown> has no descendants.
17              
18             =head1 DESCRIPTION
19              
20             This token represents something that could not be identified by the
21             tokenizer. Sometimes the lexer can fix these up, but the presence of one
22             of these in a finished parse represents something in the regular
23             expression that was not understood.
24              
25             =head1 METHODS
26              
27             This class provides the following public methods. Methods not documented
28             here are private, and unsupported in the sense that the author reserves
29             the right to change or remove them without notice.
30              
31             =cut
32              
33             package PPIx::Regexp::Token::Unknown;
34              
35 9     9   46 use strict;
  9         12  
  9         254  
36 9     9   31 use warnings;
  9         13  
  9         404  
37              
38 9     9   35 use base qw{ PPIx::Regexp::Token };
  9         13  
  9         689  
39              
40 9     9   38 use Carp ();
  9         22  
  9         179  
41 9     9   43 use PPIx::Regexp::Constant qw{ @CARP_NOT };
  9         10  
  9         766  
42 9     9   38 use PPIx::Regexp::Util;
  9         37  
  9         2425  
43              
44             our $VERSION = '0.091';
45              
46             sub __new {
47 38     38   116 my ( $class, $content, %arg ) = @_;
48              
49             defined $arg{error}
50 38 50       106 or Carp::confess( 'Programming error - error argument required' );
51              
52 38 50       152 my $self = $class->SUPER::__new( $content, %arg )
53             or return;
54              
55 38         83 $self->{error} = $arg{error};
56              
57             $self->{explanation} = defined $arg{explanation} ?
58             $arg{explanation} :
59 38 50       139 $arg{error};
60              
61 38         110 return $self;
62             }
63              
64             # Return true if the token can be quantified, and false otherwise
65 6     6 1 14 sub can_be_quantified { return };
66              
67             sub explain {
68 1     1 1 2 my ( $self ) = @_;
69 1         2 return $self->{explanation};
70             }
71              
72             =head2 is_matcher
73              
74             This method returns C<undef> because, since we could not identify the
75             token, we have no idea whether it matches anything.
76              
77             =cut
78              
79 0     0 1 0 sub is_matcher { return undef; } ## no critic (ProhibitExplicitReturnUndef)
80              
81             =head2 ordinal
82              
83             This method returns the results of the ord built-in on the content
84             (meaning, of course, the first character of the content). No attempt is
85             made to interpret the content, since after all this B<is> the unknown
86             token.
87              
88             =cut
89              
90             sub ordinal {
91 0     0 1 0 my ( $self ) = @_;
92 0         0 return ord $self->content();
93             }
94              
95             sub width {
96 0     0 1 0 return ( undef, undef );
97             }
98              
99             *__PPIX_ELEM__post_reblessing = \&PPIx::Regexp::Util::__post_rebless_error;
100              
101             # Since the lexer does not count these on the way in (because it needs
102             # the liberty to rebless them into a known class if it figures out what
103             # is going on) we count them as failures at the finalization step.
104             sub __PPIX_LEXER__finalize {
105 18     18   46 return 1;
106             }
107              
108             1;
109              
110             __END__
111              
112             =head1 SUPPORT
113              
114             Support is by the author. Please file bug reports at
115             L<https://rt.cpan.org/Public/Dist/Display.html?Name=PPIx-Regexp>,
116             L<https://github.com/trwyant/perl-PPIx-Regexp/issues>, or in
117             electronic mail to the author.
118              
119             =head1 AUTHOR
120              
121             Thomas R. Wyant, III F<wyant at cpan dot org>
122              
123             =head1 COPYRIGHT AND LICENSE
124              
125             Copyright (C) 2009-2023, 2025 by Thomas R. Wyant, III
126              
127             This program is free software; you can redistribute it and/or modify it
128             under the same terms as Perl 5.10.0. For more details, see the full text
129             of the licenses in the directory LICENSES.
130              
131             This program is distributed in the hope that it will be useful, but
132             without any warranty; without even the implied warranty of
133             merchantability or fitness for a particular purpose.
134              
135             =cut
136              
137             # ex: set textwidth=72 :