LaTeX-TOM
view release on metacpan or search on metacpan
lib/LaTeX/TOM/Parser.pm view on Meta::CPAN
\\begin\{verbatim\}
.* \Q$line\E .*
\\end\{verbatim\}
/sx
) ? 'comment' : 'text';
# if type stays the same, add to output and do nothing
if ($first || $line_type eq $mode_type) {
$output .= $line;
# handle turning off initialization stuff
$first &&= false;
$mode_type ||= $line_type;
}
# if type changes, make new node from current chunk, change mode type
# and start a new chunk
else {
push @nodes, $make_node->($mode_type, $begins, $start_pos, $output);
$start_pos += length($output); # update start position
$output = $line;
$mode_type = $line_type;
}
}
push @nodes, $make_node->($mode_type, $begins, $start_pos, $output) if defined $output;
return @nodes;
}
# Read in the contents of a text file on disk. Return in string scalar.
#
sub _readFile {
my ($file, $raise_error) = @_;
$raise_error ||= false;
my $opened = open(my $fh, '<', $file);
unless ($opened) {
croak "Cannot open `$file': $!" if $raise_error;
return undef;
}
my $contents = do { local $/; <$fh> };
close($fh);
return $contents;
}
sub _debug {
my ($message, $code) = @_;
my $DEBUG = $LaTeX::TOM::DEBUG;
return unless $DEBUG >= 1 && $DEBUG <= 2;
my ($filename, $line) = (caller)[1,2];
my $caller = join ':', (fileparse($filename))[0], $line;
warn "$caller: $message\n" if $DEBUG >= 1 && defined $message;
$code->() if $DEBUG == 2 && defined $code;
}
1;
( run in 2.251 seconds using v1.01-cache-2.11-cpan-302cb4679cc )