Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Got P<> and M<> tags working how I wanted

  • Loading branch information...
commit 1e1d18c57108ef1bc5586eb357fa8a65088f56ae 1 parent 3687aef
Andy Lester authored

Showing 2 changed files with 25 additions and 23 deletions. Show diff stats Hide diff stats

  1. 18  crank
  2. 30  s/flow-control.pod
18  crank
@@ -91,6 +91,10 @@ sub pod2html {
91 91
     $parser->output_string( \$html );
92 92
     $parser->parse_file( $podfile );
93 93
 
  94
+    # Manually adjust the stuff we passed thru earlier
  95
+    $html =~ s{P<(.+?)>}{<a href="http://perldoc.perl.org/$1.html">$1</a>}g;
  96
+    $html =~ s{M<(.+?)>}{<a href="http://search.cpan.org/perldoc?$1">$1</a>}g;
  97
+
94 98
     return $html;
95 99
 }
96 100
 
@@ -106,17 +110,15 @@ sub VERSION { '0.01' };
106 110
 sub new {
107 111
     my $self = shift->SUPER::new(@_);
108 112
 
109  
-    $self->accept_codes( qw( P M ) );
  113
+    my @passthru = qw( P M ); # P = Perldoc, M = Module
  114
+    $self->accept_codes( @passthru );
110 115
 
111 116
     my $tagmap = $self->{Tagmap};
112 117
 
113  
-    # Perldoc links
114  
-    $tagmap->{P} = qq{<a href="http://perldoc.perl.org/};
115  
-    $tagmap->{'/P'} = qq{.html">this page</a>};
116  
-
117  
-    # Module links
118  
-    $tagmap->{M} = qq{<a href="http://search.cpan.org/perldoc?};
119  
-    $tagmap->{'/M'} = qq{">here</a>};
  118
+    for my $code ( @passthru ) {
  119
+        $tagmap->{$code} = "$code<";
  120
+        $tagmap->{"/$code"} = ">";
  121
+    }
120 122
 
121 123
     return $self;
122 124
 }
30  s/flow-control.pod
Source Rendered
... ...
@@ -1,5 +1,17 @@
1 1
 =head1 Flow control
2 2
 
  3
+=head2 Four values of false
  4
+
  5
+There are four ways to have a false value in Perl:
  6
+
  7
+    my  $false = undef;
  8
+        $false = "";
  9
+        $false = 0;
  10
+        $false = "0";
  11
+
  12
+The last one is false because "0" becomes 0 in numeric
  13
+context, which is false by the third rule.
  14
+
3 15
 =head2 postfix controls
4 16
 
5 17
 A simple C<if> or C<unless> block might look like this:
@@ -18,7 +30,7 @@ This also works for C<while> and C<for>.
18 30
 
19 31
     print $i++ . "\n" while $i < 10;
20 32
 
21  
-=head2 For loops (for and foreach are really synonyms)
  33
+=head2 C<for> loops
22 34
 
23 35
 There are three styles of for loops.
24 36
 
@@ -41,7 +53,7 @@ You may see C<foreach> used in place of C<for>.  The two
41 53
 are interchangable.  Most people use C<foreach> for the
42 54
 last two styles of loops above.
43 55
 
44  
-=head2 do
  56
+=head2 C<do> blocks
45 57
 
46 58
 C<do> allows Perl to use a block where a statement is expected.
47 59
 
@@ -63,7 +75,7 @@ As a special case, C<while> runs the block at least once.
63 75
 
64 76
     do { action(); } while action_needed;
65 77
 
66  
-=head2 if/elsif/else BUT NO case
  78
+=head2 Perl has no C<switch> or C<case>
67 79
 
68 80
 If you're coming from another language, you might be used
69 81
 to C<case> statements.  Perl doesn't have them.
@@ -83,18 +95,6 @@ The closest we have is C<elsif>:
83 95
 
84 96
 There is no way to fall through cases cleanly.
85 97
 
86  
-=head2 Four values of false
87  
-
88  
-There are four ways to have a false value in Perl:
89  
-
90  
-    my  $false = undef;
91  
-        $false = "";
92  
-        $false = 0;
93  
-        $false = "0";
94  
-
95  
-The last one is false because "0" becomes 0 in numeric
96  
-context, which is false by the third rule.
97  
-
98 98
 =head2 next/last/continue/redo
99 99
 
100 100
 Consider the following loop:

0 notes on commit 1e1d18c

Please sign in to comment.
Something went wrong with that request. Please try again.