Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ilmari/podlators
base: 94fe8c4e02
...
head fork: ilmari/podlators
compare: b4b7cba355
  • 4 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 26, 2013
@ilmari Avoid duplicate method lookups
->can() returns a reference to the method, so call that directly,
instead of looking it up again.
f587a29
@ilmari Optimize ->formatting
This is a very hot method, so avoid unnecessary @_ unpacking and look up
overrides in a hash rather than using if/elsif.
aedef4c
@ilmari Inline ->formatting() into to its sole caller ad612d6
@ilmari Collapse two tr/// operations into one b4b7cba
Showing with 23 additions and 43 deletions.
  1. +23 −43 lib/Pod/Man.pm
View
66 lib/Pod/Man.pm
@@ -73,8 +73,8 @@ sub new {
$self->nbsp_for_S (1);
# Tell Pod::Simple to keep whitespace whenever possible.
- if ($self->can ('preserve_whitespace')) {
- $self->preserve_whitespace (1);
+ if (my $preserve_whitespace = $self->can ('preserve_whitespace')) {
+ $self->$preserve_whitespace (1);
} else {
$self->fullstop_space_harden (1);
}
@@ -257,12 +257,21 @@ sub _handle_text {
# Given an element name, get the corresponding method name.
sub method_for_element {
my ($self, $element) = @_;
- $element =~ tr/-/_/;
- $element =~ tr/A-Z/a-z/;
+ $element =~ tr/A-Z-/a-z_/;
$element =~ tr/_a-z0-9//cd;
return $element;
}
+# Formatting inherits negatively, in the sense that if the parent has
+# turned off guesswork, all child elements should leave it off.
+my %default_formatting = ( guesswork => 1, cleanup => 1, convert => 1 );
+my %override_formatting = (
+ Data => { guesswork => 0, cleanup => 0, convert => 0 },
+ X => { guesswork => 0, cleanup => 0 },
+ Verbatim => { guesswork => 0, literal => 1 },
+ C => { guesswork => 0, literal => 1 },
+);
+
# Handle the start of a new element. If cmd_element is defined, assume that
# we need to collect the entire tree for this element before passing it to the
# element method, and create a new tree into which we'll collect blocks of
@@ -284,13 +293,14 @@ sub _handle_element_start {
# and also depends on our parent tags. Thankfully, inside tags that
# turn off guesswork and reformatting, nothing else can turn it back
# on, so this can be strictly inherited.
- my $formatting = $$self{PENDING}[-1][1];
- $formatting = $self->formatting ($formatting, $element);
+ my $formatting = {
+ %{ $$self{PENDING}[-1][1] || \%default_formatting },
+ %{ $override_formatting{$element} || {} },
+ };
push (@{ $$self{PENDING} }, [ $attrs, $formatting, '' ]);
DEBUG > 4 and print "Pending: [", pretty ($$self{PENDING}), "]\n";
- } elsif ($self->can ("start_$method")) {
- my $method = 'start_' . $method;
- $self->$method ($attrs, '');
+ } elsif (my $start_method = $self->can ("start_$method")) {
+ $self->$start_method ($attrs, '');
} else {
DEBUG > 2 and print "No $method start method, skipping\n";
}
@@ -306,13 +316,12 @@ sub _handle_element_end {
# If we have a command handler, pull off the pending text and pass it to
# the handler along with the saved attribute hash.
- if ($self->can ("cmd_$method")) {
+ if (my $cmd_method = $self->can ("cmd_$method")) {
DEBUG > 2 and print "</$element> stops saving a tag\n";
my $tag = pop @{ $$self{PENDING} };
DEBUG > 4 and print "Popped: [", pretty ($tag), "]\n";
DEBUG > 4 and print "Pending: [", pretty ($$self{PENDING}), "]\n";
- my $method = 'cmd_' . $method;
- my $text = $self->$method ($$tag[0], $$tag[2]);
+ my $text = $self->$cmd_method ($$tag[0], $$tag[2]);
if (defined $text) {
if (@{ $$self{PENDING} } > 1) {
$$self{PENDING}[-1][2] .= $text;
@@ -320,9 +329,8 @@ sub _handle_element_end {
$self->output ($text);
}
}
- } elsif ($self->can ("end_$method")) {
- my $method = 'end_' . $method;
- $self->$method ();
+ } elsif (my $end_method = $self->can ("end_$method")) {
+ $self->$end_method ();
} else {
DEBUG > 2 and print "No $method end method, skipping\n";
}
@@ -332,34 +340,6 @@ sub _handle_element_end {
# General formatting
##############################################################################
-# Return formatting instructions for a new block. Takes the current
-# formatting and the new element. Formatting inherits negatively, in the
-# sense that if the parent has turned off guesswork, all child elements should
-# leave it off. We therefore return a copy of the same formatting
-# instructions but possibly with more things turned off depending on the
-# element.
-sub formatting {
- my ($self, $current, $element) = @_;
- my %options;
- if ($current) {
- %options = %$current;
- } else {
- %options = (guesswork => 1, cleanup => 1, convert => 1);
- }
- if ($element eq 'Data') {
- $options{guesswork} = 0;
- $options{cleanup} = 0;
- $options{convert} = 0;
- } elsif ($element eq 'X') {
- $options{guesswork} = 0;
- $options{cleanup} = 0;
- } elsif ($element eq 'Verbatim' || $element eq 'C') {
- $options{guesswork} = 0;
- $options{literal} = 1;
- }
- return \%options;
-}
-
# Format a text block. Takes a hash of formatting options and the text to
# format. Currently, the only formatting options are guesswork, cleanup, and
# convert, all of which are boolean.

No commit comments for this range

Something went wrong with that request. Please try again.