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 is a
14             L.
15              
16             C 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   65 use strict;
  9         23  
  9         290  
36 9     9   49 use warnings;
  9         20  
  9         266  
37              
38 9     9   46 use base qw{ PPIx::Regexp::Token };
  9         33  
  9         679  
39              
40 9     9   59 use Carp ();
  9         19  
  9         171  
41 9     9   55 use PPIx::Regexp::Constant qw{ @CARP_NOT };
  9         19  
  9         724  
42 9     9   60 use PPIx::Regexp::Util;
  9         18  
  9         2946  
43              
44             our $VERSION = '0.087';
45              
46             sub __new {
47 38     38   161 my ( $class, $content, %arg ) = @_;
48              
49             defined $arg{error}
50 38 50       128 or Carp::confess( 'Programming error - error argument required' );
51              
52 38 50       247 my $self = $class->SUPER::__new( $content, %arg )
53             or return;
54              
55 38         175 $self->{error} = $arg{error};
56              
57             $self->{explanation} = defined $arg{explanation} ?
58             $arg{explanation} :
59 38 50       165 $arg{error};
60              
61 38         175 return $self;
62             }
63              
64             # Return true if the token can be quantified, and false otherwise
65 6     6 1 25 sub can_be_quantified { return };
66              
67             sub explain {
68 1     1 1 3 my ( $self ) = @_;
69 1         4 return $self->{explanation};
70             }
71              
72             =head2 is_matcher
73              
74             This method returns C 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 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   50 return 1;
106             }
107              
108             1;
109              
110             __END__