| 1 | |||||||||||||||||||||||||||||||||
| 2 | # a subclass of Pod::Simple to catch X<keyword> and =head lines | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | package Mediawiki::POD::HTML; | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use base qw/Pod::Simple::HTML/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Graph::Easy; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Graph::Easy::Parser; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | $VERSION = '0.04'; | ||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | sub new | ||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 1 | my $self = Pod::Simple::HTML->new(@_); | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 1 | $self->{_mediawiki_pod_html} = {}; | |||||||||||||||||||||||||||||||
| 22 | 1 | my $storage = $self->{_mediawiki_pod_html}; | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | # we do not need an index, we will generate it ourselves | ||||||||||||||||||||||||||||||||
| 25 | 1 | $self->index(0); | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 1 | $storage->{in_headline} = 0; | |||||||||||||||||||||||||||||||
| 28 | 1 | $storage->{in_x} = 0; | |||||||||||||||||||||||||||||||
| 29 | 1 | $storage->{in_graph} = 0; | |||||||||||||||||||||||||||||||
| 30 | 1 | $storage->{headlines} = []; | |||||||||||||||||||||||||||||||
| 31 | 1 | $storage->{graph_id} = 0; | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | # the text common to all graphs | ||||||||||||||||||||||||||||||||
| 34 | 1 | $storage->{graph_common} = ''; | |||||||||||||||||||||||||||||||
| 35 | # the text of the current graph | ||||||||||||||||||||||||||||||||
| 36 | 1 | $storage->{cur_graph} = ''; | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 1 | $storage->{search} = 'http://cpan.uwinnipeg.ca/search?query=##KEYWORD##'; | |||||||||||||||||||||||||||||||
| 39 | 1 | $storage->{search_space} = undef; | |||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | # we handle these, too: | ||||||||||||||||||||||||||||||||
| 42 | 1 | $self->accept_targets('graph', 'graph-common'); | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 1 | bless $self, $class; | |||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | sub _convert_graph | ||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_convert_graph: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 49 | # when we detect the end of a "graph" section, we create CSS+HTML from it: | ||||||||||||||||||||||||||||||||
| 50 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 0 | my $storage = $self->{_mediawiki_pod_html}; | |||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | # print "# Converting to graph:\n"; | ||||||||||||||||||||||||||||||||
| 55 | # print "# '$storage->{graph_common}'\n"; | ||||||||||||||||||||||||||||||||
| 56 | # print "# '$storage->{cur_graph}'\n"; | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 0 | my $parser = Graph::Easy::Parser->new(); | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | my $graph = $parser->from_text( | ||||||||||||||||||||||||||||||||
| 61 | 0 | $storage->{graph_common} . "\n" . $storage->{cur_graph} ); | |||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 0 | $graph->set_attribute('gid', $storage->{graph_id}++); | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 0 | $self->_my_output( '<style type="text/css">' . $graph->css() . '</style>' ); | |||||||||||||||||||||||||||||||
| 66 | 0 | $self->_my_output( $graph->as_html() ); | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 0 | $storage->{in_graph} = 0; | |||||||||||||||||||||||||||||||
| 69 | 0 | $storage->{cur_graph} = ''; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | ############################################################################# | ||||||||||||||||||||||||||||||||
| 73 | # overriden methods for parsing: | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | sub _handle_element_start | ||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_handle_element_start: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||||||
| 77 | 0 | my ($self, $element_name, $attr) = @_; | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | # print STDERR "start '$element_name'\n"; | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 0 | my $storage = $self->{_mediawiki_pod_html}; | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($element_name eq 'X' && $storage->{in_x} == 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$element_name eq "X" and $storage->{"in_x"} == 0
MC/DC0%0/2
$element_name eq "X" and $storage->{"in_x"} == 0
$element_name eq "X"
$storage->{"in_x"} == 0
Truth table0%0/3
A and B
A= $element_name eq "X"B= $storage->{"in_x"} == 0
| |||||||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||||||
| 85 | 0 | $storage->{in_x} = 1; | |||||||||||||||||||||||||||||||
| 86 | 0 | $self->_my_output( '<div class="keywords">Keywords: ' ); | |||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($element_name ne 'X' && $storage->{in_x} != 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$element_name ne "X" and $storage->{"in_x"} != 0
MC/DC0%0/2
$element_name ne "X" and $storage->{"in_x"} != 0
$element_name ne "X"
$storage->{"in_x"} != 0
Truth table0%0/3
A and B
A= $element_name ne "X"B= $storage->{"in_x"} != 0
| |||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||
| 90 | # broken chain of X<> keywords | ||||||||||||||||||||||||||||||||
| 91 | 0 | $self->_my_output( '</div>' ); | |||||||||||||||||||||||||||||||
| 92 | 0 | $storage->{in_x} = 0; | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($storage->{in_graph_common} && $element_name !~ /^Data/i) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$storage->{"in_graph_common"} and not $element_name =~ /^Data/i
MC/DC0%0/2
$storage->{"in_graph_common"} and not $element_name =~ /^Data/i
$storage->{"in_graph_common"}
not $element_name =~ /^Data/i
Truth table0%0/3
A and not(B)
A= $storage->{"in_graph_common"}B= not $element_name =~ /^Data/i
| |||||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||||
| 97 | 0 | $storage->{in_graph_common} = 0; | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($storage->{in_graph} && $element_name !~ /^Data/i) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$storage->{"in_graph"} and not $element_name =~ /^Data/i
MC/DC0%0/2
$storage->{"in_graph"} and not $element_name =~ /^Data/i
$storage->{"in_graph"}
not $element_name =~ /^Data/i
Truth table0%0/3
A and not(B)
A= $storage->{"in_graph"}B= not $element_name =~ /^Data/i
| |||||||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||||||
| 102 | 0 | $self->_convert_graph(); | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | # =for graph and =begin graph sections | ||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($element_name eq 'for' && ($attr->{target} || '') eq 'graph') | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$element_name eq "for" and ($attr->{"target"} || "") eq "graph"
$attr->{'target'} || ''
MC/DC0%0/2
$element_name eq "for" and ($attr->{"target"} || "") eq "graph"
$element_name eq "for"
$attr->{'target'}
Truth table0%0/3
A and B
A= $element_name eq "for"B= $attr->{'target'}
| |||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||
| 107 | 0 | $storage->{in_graph} = 1; | |||||||||||||||||||||||||||||||
| 108 | 0 | $storage->{cur_graph} = ''; | |||||||||||||||||||||||||||||||
| 109 | 0 | return; | |||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | # =for graph-common and =begin graph sections | ||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ($element_name eq 'for' && ($attr->{target} || '') eq 'graph-common') | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$element_name eq "for" and ($attr->{"target"} || "") eq "graph-common"
$attr->{'target'} || ''
MC/DC0%0/2
$element_name eq "for" and ($attr->{"target"} || "") eq "graph-common"
$element_name eq "for"
$attr->{'target'}
Truth table0%0/3
A and B
A= $element_name eq "for"B= $attr->{'target'}
| |||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||
| 115 | 0 | $storage->{in_graph_common} = 1; | |||||||||||||||||||||||||||||||
| 116 | 0 | $storage->{graph_common} = ''; | |||||||||||||||||||||||||||||||
| 117 | 0 | return; | |||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ($element_name =~ /^head/) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||
| 122 | 0 | push @{ $storage->{headlines} }, $element_name . ' '; | |||||||||||||||||||||||||||||||
| 123 | 0 | $storage->{in_headline} = 1; | |||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 0 | $self->SUPER::_handle_element_start($element_name, $attr); | |||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | sub _handle_element_end | ||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_handle_element_end: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 131 | 0 | my ($self, $element_name) = @_; | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | # print STDERR "end '$element_name'\n"; | ||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | 0 | my $storage = $self->{_mediawiki_pod_html}; | |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ($element_name =~ /^head/) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||
| 139 | 0 | $storage->{in_headline} = 0; | |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ($element_name eq 'Document') | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $self->_convert_graph() if $storage->{in_graph}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 0 | $self->SUPER::_handle_element_end($element_name); | |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub _handle_text { | ||||||||||||||||||||||||||||||
|
Subroutine
_handle_text: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||
| 150 | 0 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | # print STDERR "text '$text'\n"; | ||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | 0 | my $storage = $self->{_mediawiki_pod_html}; | |||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ($storage->{in_headline}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||||||
| 157 | 0 | $storage->{headlines}->[-1] .= $text; | |||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ($storage->{in_graph}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||
| 161 | 0 | $storage->{cur_graph} .= $text; | |||||||||||||||||||||||||||||||
| 162 | 0 | return; | |||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ($storage->{in_graph_common}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||
| 166 | 0 | $storage->{graph_common} .= $text; | |||||||||||||||||||||||||||||||
| 167 | 0 | return; | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if ($storage->{in_x}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||
| 171 | 0 | my $url = $storage->{search}; | |||||||||||||||||||||||||||||||
| 172 | 0 | my $t = $text; | |||||||||||||||||||||||||||||||
| 173 | 0 | $t =~ s/&/∓/; | |||||||||||||||||||||||||||||||
| 174 | 0 | $t =~ s/'/&squot;/; | |||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ($url =~ /##KEYWORD##/) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||||||
| 177 | 0 | $url =~ s/##KEYWORD##/$t/g; | |||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $url =~ s/ /_/g unless defined $storage->{search_space}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||
| 180 | else | ||||||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||||||
| 182 | 0 | $url .= $t; | |||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $url =~ s/ /+/g unless defined $storage->{search_space}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||
| 185 | # make spaces safe | ||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $url =~ s/ /$storage->{search_space}/g if defined $storage->{search_space}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 187 | 0 | $self->_my_output( "<a class='keyword' href='$url'>$text</a>" ); | |||||||||||||||||||||||||||||||
| 188 | 0 | return; | |||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | 0 | $self->SUPER::_handle_text($text); | |||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | sub get_headlines | ||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
get_headlines: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 196 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | 0 | my $storage = $self->{_mediawiki_pod_html}; | |||||||||||||||||||||||||||||||
| 199 | 0 | $storage->{headlines}; | |||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | sub keyword_search_url | ||||||||||||||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||||||||||||
| 204 | my $self = shift; | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | my $storage = $self->{_mediawiki_pod_html}; | ||||||||||||||||||||||||||||||||
| 207 | $storage->{search} = $_[0] if defined $_[0]; | ||||||||||||||||||||||||||||||||
| 208 | # can be undef, too | ||||||||||||||||||||||||||||||||
| 209 | $storage->{search_space} = $_[1] if defined @_ == 2; | ||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | wantarray ? | ||||||||||||||||||||||||||||||||
| 212 | ($storage->{search}, $storage->{search_space}) : $storage->{search}; | ||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | sub _my_output | ||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||
| 217 | my $self = shift; | ||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | print {$self->{'output_fh'}} $_[0]; | ||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||
| 222 | 1; | ||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | __END__ | ||||||||||||||||||||||||||||||||