File Coverage

blib/lib/Pod/Elemental/Transformer/WikiDoc.pm
Criterion Covered Total %
statement 30 30 100.0
branch 2 4 50.0
condition 5 9 55.5
subroutine 6 6 100.0
pod 1 1 100.0
total 44 50 88.0


line stmt bran cond sub pod time code
1             package Pod::Elemental::Transformer::WikiDoc;
2             {
3             $Pod::Elemental::Transformer::WikiDoc::VERSION = '0.093003';
4             }
5 1     1   1206020 use Moose;
  1         3  
  1         8  
6             with 'Pod::Elemental::Transformer';
7             # ABSTRACT: a transformer to replace "wikidoc" data regions with Pod5 elements
8              
9              
10 1     1   6299 use namespace::autoclean;
  1         2  
  1         10  
11              
12 1     1   72 use Moose::Autobox;
  1         3  
  1         9  
13              
14 1     1   584 use Pod::Elemental::Types qw(FormatName);
  1         2  
  1         11  
15 1     1   2149 use Pod::WikiDoc;
  1         98354  
  1         328  
16              
17              
18             has format_name => (
19             is => 'ro',
20             isa => FormatName,
21             default => 'wikidoc',
22             );
23              
24              
25             sub transform_node {
26 1     1 1 75883 my ($self, $node) = @_;
27 1         41 my $children = $node->children;
28              
29 1         18 PASS: for (my $i = 0; $i < $children->length; $i++) {
30 29         1394 my $para = $children->[$i];
31 29 50 66     335 next unless $para->isa('Pod::Elemental::Element::Pod5::Region')
      66        
32             and ! $para->is_pod
33             and $para->format_name eq $self->format_name;
34              
35 2 50 33     83 confess "wikidoc transformer expects wikidoc region to contain 1 Data para"
36             unless $para->children->length == 1
37             and $para->children->[0]->isa('Pod::Elemental::Element::Pod5::Data');
38              
39 2         194 my $text = $para->children->[0]->content;
40 2         113 my $parser = Pod::WikiDoc->new;
41 2         1996 my $new_pod = $parser->convert($para->as_pod_string);
42              
43 2         77758 $new_pod =~ s/^# Generated by Pod::WikiDoc version \S+$//sgm;
44              
45 2         32 my $new_doc = Pod::Elemental->read_string($new_pod);
46 2         84386 Pod::Elemental::Transformer::Pod5->transform_node($new_doc);
47 2         139207 $new_doc->children->shift
48             while
49             $new_doc->children->[0]->isa('Pod::Elemental::Element::Pod5::Nonpod');
50              
51 2         505 splice @$children, $i, 1, $new_doc->children->flatten;
52             }
53              
54 1         7 return $node;
55             }
56              
57             1;
58              
59             __END__
60              
61             =pod
62              
63             =head1 NAME
64              
65             Pod::Elemental::Transformer::WikiDoc - a transformer to replace "wikidoc" data regions with Pod5 elements
66              
67             =head1 VERSION
68              
69             version 0.093003
70              
71             =head1 SYNOPSIS
72              
73             my $document = Pod::Elemental->read_string( $string );
74             Pod::Elemental::Transformer::Pod5->new->transform_node( $document );
75              
76             Pod::Elemental::Transformer::WikiDoc->new->transform_node( $document );
77              
78             ...and if you had a section like this:
79              
80             =begin wikidoc
81              
82             == Look, a header!
83              
84             * Foo
85             * Bar
86             * Baz
87              
88             =end wikidoc
89              
90             ...you now have something more like this:
91              
92             =head2 Look, a header!
93              
94             =over 4
95            
96             =item Foo
97              
98             =item Bar
99              
100             =item Baz
101              
102             =back
103              
104             For complete documentation on this dialect, see L<Pod::WikiDoc>.
105              
106             Possibly the most succinct, powerful use case is this:
107              
108             =head2 some_method
109              
110             This B<public> method takes the following arguments:
111              
112             =for wikidoc
113             * name
114             * rank
115             * serial_number
116              
117             =cut
118              
119             =head1 ATTRIBUTES
120              
121             =head2 format_name
122              
123             This attribute indicates the format name of regions to be transformed from
124             WikiDoc. By default, the transformer will look for regions of the format
125             "wikidoc."
126              
127             =head1 METHODS
128              
129             =head2 transform_node
130              
131             =head1 AUTHOR
132              
133             Ricardo SIGNES <rjbs@cpan.org>
134              
135             =head1 COPYRIGHT AND LICENSE
136              
137             This software is copyright (c) 2013 by Ricardo SIGNES.
138              
139             This is free software; you can redistribute it and/or modify it under
140             the same terms as the Perl 5 programming language system itself.
141              
142             =cut