]> iEval git - pod-constants.git/commitdiff
Make code shorter and wider
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 17 Jul 2015 11:11:53 +0000 (14:11 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 17 Jul 2015 12:31:33 +0000 (15:31 +0300)
lib/Pod/Constants.pm
t/01-constants.t

index 3395a9c2652bafb209f56e6b88ba6ea164f0a127..3e24fea847f0afe4b580adcccfe7c405f828e27e 100644 (file)
@@ -10,7 +10,6 @@ use strict;
 use warnings;
 
 use base qw(Pod::Parser Exporter);
-use Data::Dumper;
 use Carp;
 
 our $VERSION = 0.17;
@@ -25,13 +24,11 @@ sub end_input {
 
        return unless $parser->{active};
 
-       print "Found end of $parser->{active}\n" if ($parser->{DEBUG});
+       print "Found end of $parser->{active}\n" if $parser->{DEBUG};
        my $whereto = $parser->{wanted_pod_tags}->{$parser->{active}};
-       print "\$_ will be set to:\n---\n$parser->{paragraphs}\n---\n"
-         if ($parser->{DEBUG});
+       print "\$_ will be set to:\n---\n$parser->{paragraphs}\n---\n" if $parser->{DEBUG};
 
-       $parser->{paragraphs} =~ s/^\s*|\s*$//gs
-         if $parser->{trimmed_tags}->{$parser->{active}};
+       $parser->{paragraphs} =~ s/^\s*|\s*$//gs if $parser->{trimmed_tags}->{$parser->{active}};
 
        if (ref $whereto eq "CODE") {
                print "calling sub\n" if $parser->{DEBUG};
@@ -47,14 +44,12 @@ sub end_input {
        } elsif (ref $whereto eq "HASH") {
                print "inserting into hash\n" if $parser->{DEBUG};
                # Oh, sorry, should I be in LISP101?
-               %$whereto = (map { map { s/^\s*|\s*$//g; $_ }
-                                                        split /=>/, $_ }
-                                          grep m/^
-                                                         ( (?:[^=]|=[^>])+ )   # scan up to "=>"
-                                                         =>
-                                                         ( (?:[^=]|=[^>])+ =? )# don't allow more "=>"'s
-                                                         $/x,
-                                        split /\n/, $parser->{paragraphs});
+               %$whereto = (
+                       map { map { s/^\s*|\s*$//g; $_ } split /=>/, $_ } grep m/^
+                                        ( (?:[^=]|=[^>])+ )   # scan up to "=>"
+                                        =>
+                                        ( (?:[^=]|=[^>])+ =? )# don't allow more "=>"'s
+                                        $/x, split /\n/, $parser->{paragraphs});
        } else { die $whereto }
        $parser->{active} = undef;
 }
@@ -65,50 +60,38 @@ sub command {
 
        $paragraph =~ s/(?:\r\n|\n\r)/\n/g;
 
-       print "Got command =$command, value=$paragraph\n"
-         if $parser->{DEBUG};
+       print "Got command =$command, value=$paragraph\n" if $parser->{DEBUG};
 
        $parser->end_input() if $parser->{active};
 
-       my $does_she_want_it_sir;
-
        my ($lookup);
        # first check for a catch-all for this command type
        if ( exists $parser->{wanted_pod_tags}->{"*$command"} ) {
                $parser->{paragraphs} = $paragraph;
                $parser->{active} = "*$command";
-               $does_she_want_it_sir = "oohw";
-
        } elsif ($command =~ m/^(head\d+|item|(for|begin))$/) {
                if ( $2 ) {
                        # if it's a "for" or "begin" section, the title is the
                        # first word only
-                       ($lookup, $parser->{paragraphs}) =
-                         ($paragraph =~ m/^\s*(\S*)\s*(.*)/s);
+                       ($lookup, $parser->{paragraphs}) = $paragraph =~ m/^\s*(\S*)\s*(.*)/s;
                } else {
                        # otherwise, it's up to the end of the line
-                       ($lookup, $parser->{paragraphs})
-                         = ($paragraph =~ m/^\s*(\S[^\n]*?)\s*\n(.*)$/s);
+                       ($lookup, $parser->{paragraphs}) = $paragraph =~ m/^\s*(\S[^\n]*?)\s*\n(.*)$/s;
                }
 
                # Look for a match by name
-               if (defined $lookup
-                         and exists $parser->{wanted_pod_tags}->{$lookup}) {
+               if (defined $lookup && exists $parser->{wanted_pod_tags}->{$lookup}) {
                        print "Found $lookup\n" if ($parser->{DEBUG});
                        $parser->{active} = $lookup;
-                       $does_she_want_it_sir = "suits you sir";
+               } elsif ($parser->{DEBUG}) {
+                       local $^W = 0;
+                       print "Ignoring =$command $paragraph (lookup = $lookup)\n"
                }
 
        } else {
                # nothing
                print "Ignoring =$command (not known)\n" if $parser->{DEBUG};
        }
-
-       {
-               local $^W = 0;
-               print "Ignoring =$command $paragraph (lookup = $lookup)\n"
-                 if (!$does_she_want_it_sir and $parser->{DEBUG})
-         }
 }
 
 # Pod::Parser overloaded verbatim
@@ -116,13 +99,10 @@ sub verbatim {
        my ($parser, $paragraph, $line_num) = @_;
        $paragraph =~ s/(?:\r\n|\n\r)/\n/g;
 
-       print("Got paragraph: $paragraph ("
-                       .($parser->{active}?"using":"ignoring").")\n")
-         if $parser->{DEBUG};
+       my $status = $parser->{active} ? "using" : "ignoring";
+       print "Got paragraph: $paragraph ($status)\n" if $parser->{DEBUG};
 
-       if (defined $parser->{active}) {
-               $parser->{paragraphs} .= $paragraph;
-       }
+       $parser->{paragraphs} .= $paragraph if defined $parser->{active}
 }
 
 # Pod::Parser overloaded textblock
@@ -142,9 +122,7 @@ sub import {
        }
        $source_file ||= $0;
 
-       ( -f $source_file )
-         or croak ("Cannot find source file (guessed $source_file) for"
-                               ." package ".caller());
+       croak "Cannot find source file (guessed $source_file) for package ".caller unless -f $source_file;
 
        # nasty tricks with the stack so we don't have to be silly with
        # caller()
@@ -168,11 +146,9 @@ sub import_from_file {
 
        $parser->add_hook(@_);
 
-       print "Pod::Parser: DEBUG: Opening $filename for reading\n"
-         if $parser->{DEBUG};
+       print "Pod::Parser: DEBUG: Opening $filename for reading\n" if $parser->{DEBUG};
        my $fh = new IO::Handle;
-       open $fh, "<$filename"
-         or die ("cannot open $filename for reading; $!");
+       open $fh, "<$filename" or die "cannot open $filename for reading; $!";
 
        $parser->parse_from_filehandle($fh, \*STDOUT);
 
@@ -181,12 +157,10 @@ sub import_from_file {
 
 sub add_hook {
        my $parser;
-       if ( UNIVERSAL::isa($_[0], __PACKAGE__) ) {
+       if (UNIVERSAL::isa($_[0], __PACKAGE__)) {
                $parser = shift;
        } else {
-               $parser = $parsers{caller()}
-                 or die("add_hook called, but don't know what for - "
-                                ."caller = ".caller());
+               $parser = $parsers{caller()} or die "add_hook called, but don't know what for - caller = ".caller;
        }
        while (my ($pod_tag, $var) = splice @_, 0, 2) {
                #print "$pod_tag: $var\n";
@@ -199,15 +173,11 @@ sub add_hook {
                        #%wanted_pod_tags{@tags}
                } else {
                        if ((ref $var) =~ /^(?:SCALAR|CODE|ARRAY|HASH)$/) {
-                               print "Will look for $pod_tag.\n"
-                                 if ($parser->{DEBUG});
+                               print "Will look for $pod_tag.\n" if $parser->{DEBUG};
                                $parser->{wanted_pod_tags}->{$pod_tag} = $var;
-                               $parser->{trimmed_tags}->{$pod_tag} = 1
-                                 if $parser->{trim_next};
+                               $parser->{trimmed_tags}->{$pod_tag} = 1 if $parser->{trim_next};
                        } else {
-                               die ("Sorry - need a reference to import POD "
-                                          ."sections into, not the scalar value $var"
-                                          ." importing $pod_tag into ".caller());
+                               die "Sorry - need a reference to import POD sections into, not the scalar value $var"
                        }
                }
        }
@@ -218,9 +188,7 @@ sub delete_hook {
        if ( UNIVERSAL::isa($_[0], __PACKAGE__) ) {
                $parser = shift;
        } else {
-               $parser = $parsers{caller()}
-                 or die("delete_hook called, but don't know what for - "
-                                ."caller = ".caller());
+               $parser = $parsers{caller()} or die "delete_hook called, but don't know what for - caller = ".caller;
        }
        while ( my $label = shift ) {
                delete $parser->{wanted_pod_tags}->{$label};
@@ -239,7 +207,7 @@ Pod::Constants - Include constants from POD
 
 =head1 SYNOPSIS
 
- our ($myvar $VERSION @myarray $html %myhash);
+ our ($myvar, $VERSION, @myarray, $html, %myhash);
 
  use Pod::Constants -trim => 1,
      'Pod Section Name' => \$myvar,
index dfe8cf69f7097dfdfccf0d5d6e3097b796c4de24..b9de1b3fb2e14e1c08d25e265dfccb8bd7660e3d 100644 (file)
@@ -70,7 +70,7 @@ Pod::Constants->import (SYNOPSIS => sub {
 package main;
 open NEWPKG, ">t/TestManPage.pm" or die $!;
 # why define your test results when you can read them in from POD?
-$section_1 =~ s/myhash\)/myhash %myhash2)/;
+$section_1 =~ s/myhash\)/myhash, %myhash2)/;
 $section_1 =~ s/myhash;/myhash, "%myhash\'s value after the above:" => sub { %myhash2 = eval };/;
 print NEWPKG "package TestManPage;\n$section_1\n2.818;\n";
 close NEWPKG;
This page took 0.040377 seconds and 4 git commands to generate.