1# Copyright 2009, 2010, 2011 Kevin Ryde 2 3# This file is part of Pod-MinimumVersion. 4 5# Pod-MinimumVersion is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by the 7# Free Software Foundation; either version 3, or (at your option) any later 8# version. 9# 10# Pod-MinimumVersion is distributed in the hope that it will be useful, but 11# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13# for more details. 14# 15# You should have received a copy of the GNU General Public License along 16# with Pod-MinimumVersion. If not, see <http://www.gnu.org/licenses/>. 17 18 19package Pod::MinimumVersion::Parser; 20use 5.004; 21use strict; 22use vars '$VERSION', '@ISA'; 23 24use Pod::Parser; 25@ISA = ('Pod::Parser'); 26 27$VERSION = 50; 28 29# uncomment this to run the ### lines 30#use Smart::Comments; 31 32sub new { 33 my $class = shift; 34 my $self = $class->SUPER::new(@_); 35 $self->errorsub ('error_handler'); # method name 36 return $self; 37} 38sub error_handler { 39 my ($self, $errmsg) = @_; 40 ### PMV error_handler() 41 return 1; # error handled 42} 43 44# sub begin_input { 45# print "begin_input\n"; 46# } 47# sub end_input { 48# print "end_input\n"; 49# } 50 51sub parse_from_string { 52 my ($self, $str) = @_; 53 ### PMV parse_from_string() 54 55 require IO::String; 56 my $fh = IO::String->new ($str); 57 $self->{_INFILE} = "(string)"; 58 return $self->parse_from_filehandle ($fh); 59} 60 61my %command_does_not_interpolate = (for => 1, # free form text 62 begin => 1, # formatname not text 63 end => 1, 64 pod => 1, # text ignored 65 cut => 1, # text ignored 66 encoding => 1, # encoding name not text 67 ); 68sub command { 69 my ($self, $command, $text, $linenum, $paraobj) = @_; 70 ### PMV command() 71 ### $command 72 ### $text 73 ### $linenum 74 75 # If =foo command at EOF with no more chars, including no trailing 76 # newline, then $text is undef (circa Pod::Parser 1.37 at least). 77 # 78 if (defined $text) { 79 if ($command eq 'for' 80 && $text =~ /^Pod::MinimumVersion\s+use\s+(v?[0-9._]+)/) { 81 $self->{'pmv'}->{'for_version'} = version->new($1); 82 } 83 84 foreach my $func (@{$self->{'checks'}->{'command'}}) { 85 $func->($self->{'pmv'}, $command, $text, $paraobj); 86 } 87 88 unless ($command_does_not_interpolate{$command}) { 89 $self->interpolate ($text, $linenum); 90 } 91 } 92 return ''; 93} 94 95sub verbatim { 96 ### PMV verbatim() 97 return ''; 98} 99 100sub textblock { 101 my ($self, $text, $linenum, $paraobj) = @_; 102 ### PMV textblock() 103 ### $text 104 return $self->interpolate ($text, $linenum); 105} 106 107sub interior_sequence { 108 my ($self, $command, $arg, $seq_obj) = @_; 109 ### interior 110 ### $command 111 ### $arg 112 ### $seq_obj 113 ### raw_text: $seq_obj->raw_text 114 ### left: $seq_obj->left_delimiter 115 ### nested: do { my $outer = $seq_obj->nested; $outer && $outer->cmd_name } 116 117 # J<> from Pod::MultiLang -- doubled C<<>> or L<|display> are allowed 118 # ENHANCE-ME: might prefer to make parse_tree() not descend into J<> at 119 # all, but it doesn't seem setup for that 120 my $outer; 121 if ($command eq 'J' 122 || (($outer = $seq_obj->nested) && $outer->cmd_name eq 'J')) { 123 return ''; 124 } 125 126 foreach my $func (@{$self->{'checks'}->{'interior_sequence'}}) { 127 $func->($self->{'pmv'}, $command, $arg, $seq_obj); 128 } 129 return ''; 130} 131 1321; 133__END__ 134 135=for stopwords Ryde Pod-MinimumVersion 136 137=head1 NAME 138 139Pod::MinimumVersion::Parser - parser used by Pod::MinimumVersion 140 141=head1 DESCRIPTION 142 143This is an internal part of C<Pod::MinimumVersion>, not meant for other use. 144 145=head1 SEE ALSO 146 147L<Pod::MinimumVersion> 148 149=head1 HOME PAGE 150 151http://user42.tuxfamily.org/pod-minimumversion/index.html 152 153=head1 COPYRIGHT 154 155Copyright 2009, 2010, 2011 Kevin Ryde 156 157Pod-MinimumVersion is free software; you can redistribute it and/or modify it 158under the terms of the GNU General Public License as published by the Free 159Software Foundation; either version 3, or (at your option) any later 160version. 161 162Pod-MinimumVersion is distributed in the hope that it will be useful, but 163WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 164or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 165more details. 166 167You should have received a copy of the GNU General Public License along with 168Pod-MinimumVersion. If not, see <http://www.gnu.org/licenses/>. 169 170=cut 171