line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl6::Pod::To::Test; |
2
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
3
|
2
|
|
|
2
|
|
91784
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
55
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
5
|
2
|
|
|
2
|
|
555
|
use Perl6::Pod::To; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
62
|
|
6
|
2
|
|
|
2
|
|
10
|
use base 'Perl6::Pod::To'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
234
|
|
7
|
|
|
|
|
|
|
sub __default_method { |
8
|
0
|
|
|
0
|
|
|
my $self = shift; |
9
|
0
|
|
|
|
|
|
my $n = shift; |
10
|
0
|
0
|
|
|
|
|
unless (defined $n) { |
11
|
0
|
|
|
|
|
|
warn "default" . $n; |
12
|
2
|
|
|
2
|
|
11
|
use Data::Dumper; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
516
|
|
13
|
0
|
|
|
|
|
|
warn Dumper([caller(0)]); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#detect output format |
17
|
|
|
|
|
|
|
# Perl6::Pod::To::DocBook -> to_docbook |
18
|
0
|
|
|
|
|
|
my $export_method ='to_xhtml'; |
19
|
0
|
0
|
0
|
|
|
|
unless ( $export_method && UNIVERSAL::can($n, $export_method) ) { |
20
|
0
|
|
|
|
|
|
my $method = $self->__get_method_name($n); |
21
|
0
|
|
|
|
|
|
die ref($self) |
22
|
|
|
|
|
|
|
. ": Method '$method' for class " |
23
|
|
|
|
|
|
|
. ref($n) |
24
|
|
|
|
|
|
|
. " not implemented. But also can't found export method ". ref($n) . "::$export_method"; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
#call method for export |
27
|
0
|
|
|
|
|
|
$n->$export_method($self); |
28
|
|
|
|
|
|
|
#src_name may be not eq for name |
29
|
|
|
|
|
|
|
# ie/ item2, head5 |
30
|
0
|
|
|
|
|
|
my $name = $n->{name}; |
31
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::isa($n, 'Perl6::Pod::FormattingCode')) { |
32
|
0
|
|
|
|
|
|
$name = "$name<>"; |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
|
push @{ $self->{ $name }}, $n; |
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
0
|
|
|
|
if ( exists ($n->{src_name}) && ($name ne $n->{src_name}) ) { |
36
|
0
|
|
|
|
|
|
push @{ $self->{ $n->{src_name} }}, $n; |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
package Perl6::Pod::Test; |
41
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Perl6::Pod::Test - test lib |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
42
|
|
56
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
59
|
|
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
2
|
|
10
|
use Test::More; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
50
|
|
59
|
2
|
|
|
2
|
|
614
|
use Perl6::Pod::Writer; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
44
|
|
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
2
|
|
1109
|
use Perl6::Pod::To::DocBook; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
57
|
|
62
|
2
|
|
|
2
|
|
643
|
use Perl6::Pod::To::XHTML; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
53
|
|
63
|
2
|
|
|
2
|
|
1041
|
use Perl6::Pod::To::Latex; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
60
|
|
64
|
2
|
|
|
2
|
|
1491
|
use XML::Flow; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub parse_to_docbook { |
67
|
|
|
|
|
|
|
shift if ref($_[0]); |
68
|
|
|
|
|
|
|
my ( $text) = @_; |
69
|
|
|
|
|
|
|
my $out = ''; |
70
|
|
|
|
|
|
|
open( my $fd, ">", \$out ); |
71
|
|
|
|
|
|
|
my $renderer = new Perl6::Pod::To::DocBook:: |
72
|
|
|
|
|
|
|
writer => new Perl6::Pod::Writer( out => $fd, escape=>'xml' ), |
73
|
|
|
|
|
|
|
out_put => \$out, |
74
|
|
|
|
|
|
|
doctype => 'chapter', |
75
|
|
|
|
|
|
|
header => 0; |
76
|
|
|
|
|
|
|
$renderer->parse( \$text, default_pod=>1 ); |
77
|
|
|
|
|
|
|
return wantarray ? ( $out, $renderer ) : $out; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub parse_to_latex { |
83
|
|
|
|
|
|
|
shift if ref($_[0]); |
84
|
|
|
|
|
|
|
my ( $text) = @_; |
85
|
|
|
|
|
|
|
my $out = ''; |
86
|
|
|
|
|
|
|
open( my $fd, ">", \$out ); |
87
|
|
|
|
|
|
|
my $renderer = new Perl6::Pod::To::Latex:: |
88
|
|
|
|
|
|
|
writer => new Perl6::Pod::Writer::Latex( out => $fd, escape=>'latex' ), |
89
|
|
|
|
|
|
|
out_put => \$out, |
90
|
|
|
|
|
|
|
header => 0; |
91
|
|
|
|
|
|
|
$renderer->parse( \$text, default_pod=>1 ); |
92
|
|
|
|
|
|
|
return wantarray ? ( $out, $renderer ) : $out; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub parse_to_xhtml { |
96
|
|
|
|
|
|
|
shift if ref($_[0]); |
97
|
|
|
|
|
|
|
my ( $text) = @_; |
98
|
|
|
|
|
|
|
my $out = ''; |
99
|
|
|
|
|
|
|
open( my $fd, ">", \$out ); |
100
|
|
|
|
|
|
|
my $renderer = new Perl6::Pod::To::XHTML:: |
101
|
|
|
|
|
|
|
writer => new Perl6::Pod::Writer( out => $fd, escape=>'xml' ), |
102
|
|
|
|
|
|
|
out_put => \$out, |
103
|
|
|
|
|
|
|
doctype => 'xhtml', |
104
|
|
|
|
|
|
|
header => 0; |
105
|
|
|
|
|
|
|
$renderer->parse( \$text, default_pod=>1 ); |
106
|
|
|
|
|
|
|
return wantarray ? ( $out, $renderer ) : $out; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub parse_to_test { |
110
|
|
|
|
|
|
|
shift if ref($_[0]); |
111
|
|
|
|
|
|
|
my ( $text, %args) = @_; |
112
|
|
|
|
|
|
|
my $out = ''; |
113
|
|
|
|
|
|
|
open( my $fd, ">", \$out ); |
114
|
|
|
|
|
|
|
my $renderer = new Perl6::Pod::To::Test:: |
115
|
|
|
|
|
|
|
writer => new Perl6::Pod::Writer( out => $fd, escape=>'xml' ), |
116
|
|
|
|
|
|
|
out_put => \$out, |
117
|
|
|
|
|
|
|
doctype => 'xhtml', |
118
|
|
|
|
|
|
|
header => 0; |
119
|
|
|
|
|
|
|
$renderer->parse( \$text, default_pod=>1 ) unless exists $args{no_parse}; |
120
|
|
|
|
|
|
|
return wantarray ? ( $out, $renderer ) : $renderer; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
sub new { |
124
|
|
|
|
|
|
|
my $class = shift; |
125
|
|
|
|
|
|
|
$class = ref $class if ref $class; |
126
|
|
|
|
|
|
|
my $self = bless( {@_}, $class ); |
127
|
|
|
|
|
|
|
return $self; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 is_deeply_xml ,,"text" |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Check xml without attribute values and character data |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _xml_to_ref { |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# my $self = shift; |
140
|
|
|
|
|
|
|
my $xml = shift; |
141
|
|
|
|
|
|
|
my %tags; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#collect tags names; |
144
|
|
|
|
|
|
|
map { $tags{$_}++ } $xml =~ m/<(\w+)/gis; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
#make handlers |
147
|
|
|
|
|
|
|
our $res; |
148
|
|
|
|
|
|
|
for ( keys %tags ) { |
149
|
|
|
|
|
|
|
my $name = $_; |
150
|
|
|
|
|
|
|
$tags{$_} = sub { |
151
|
|
|
|
|
|
|
my $attr = shift || {}; |
152
|
|
|
|
|
|
|
return $res = { |
153
|
|
|
|
|
|
|
name => $name, |
154
|
|
|
|
|
|
|
attr => [ keys %$attr ], |
155
|
|
|
|
|
|
|
content => [ grep { ref $_ } @_ ] |
156
|
|
|
|
|
|
|
}; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
my $rd = new XML::Flow:: \$xml; |
160
|
|
|
|
|
|
|
$rd->read( \%tags ); |
161
|
|
|
|
|
|
|
$res; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub xml_ref { |
165
|
|
|
|
|
|
|
my $self = shift; |
166
|
|
|
|
|
|
|
my $xml = shift; |
167
|
|
|
|
|
|
|
my %tags; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
#collect tags names; |
170
|
|
|
|
|
|
|
map { $tags{$_}++ } $xml =~ m/<(\w+)/gis; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
#make handlers |
173
|
|
|
|
|
|
|
our $res; |
174
|
|
|
|
|
|
|
for ( keys %tags ) { |
175
|
|
|
|
|
|
|
my $name = $_; |
176
|
|
|
|
|
|
|
$tags{$_} = sub { |
177
|
|
|
|
|
|
|
my $attr = shift || {}; |
178
|
|
|
|
|
|
|
return $res = { |
179
|
|
|
|
|
|
|
name => $name, |
180
|
|
|
|
|
|
|
attr => $attr, |
181
|
|
|
|
|
|
|
content => [ grep { ref $_ } @_ ] |
182
|
|
|
|
|
|
|
}; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
my $rd = new XML::Flow:: \$xml; |
186
|
|
|
|
|
|
|
$rd->read( \%tags ); |
187
|
|
|
|
|
|
|
$res; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub is_deeply_xml { |
192
|
|
|
|
|
|
|
my $test = shift; |
193
|
|
|
|
|
|
|
my ( $got, $exp, @params ) = @_; |
194
|
|
|
|
|
|
|
unless ( is_deeply $test->xml_ref($got), $test->xml_ref($exp), @params ) { |
195
|
|
|
|
|
|
|
diag "got:", "<" x 40; |
196
|
|
|
|
|
|
|
diag $got; |
197
|
|
|
|
|
|
|
diag "expected:", ">" x 40; |
198
|
|
|
|
|
|
|
diag $exp; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; |