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