| 1 | # | ||||||||||||||
| 2 | # This file is part of Pod-Elemental-Transformer-List-Converter | ||||||||||||||
| 3 | # | ||||||||||||||
| 4 | # This software is Copyright (c) 2012 by Chris Weyl. | ||||||||||||||
| 5 | # | ||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||
| 7 | # | ||||||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||
| 9 | # | ||||||||||||||
| 10 | package Pod::Elemental::Transformer::List::Converter; | ||||||||||||||
| 11 | { | ||||||||||||||
| 12 | 2 | $Pod::Elemental::Transformer::List::Converter::VERSION = '0.001'; | |||||||||||||
| 13 | } | ||||||||||||||
| 14 | |||||||||||||||
| 15 | # ABSTRACT: Convert a list to... something else | ||||||||||||||
| 16 | |||||||||||||||
| 17 | 2 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 2 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 2 | ▶ | use Moose::Autobox; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | |||||||||||||||
| 21 | 2 | ▶ | use Pod::Elemental; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 2 | ▶ | use Pod::Elemental::Transformer 0.102361; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | 2 | with 'Pod::Elemental::Transformer'; | |||||||||||||
| 25 | |||||||||||||||
| 26 | # debugging... | ||||||||||||||
| 27 | #use Smart::Comments; | ||||||||||||||
| 28 | |||||||||||||||
| 29 | |||||||||||||||
| 30 | 2 | has command => (is => 'rw', isa => 'Str', default => 'head2'); | |||||||||||||
| 31 | |||||||||||||||
| 32 | |||||||||||||||
| 33 | 4 | ▶ | sub transform_node { | ||||||||||||
|
Subroutine
transform_node: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||
| 34 | 4 | my ($self, $node) = @_; | |||||||||||||
| 35 | |||||||||||||||
| 36 | 4 | my %drop = map { $_ => 1 } qw{ over back }; | |||||||||||||
| 37 | 4 | my @elements; | |||||||||||||
| 38 | |||||||||||||||
| 39 | ### get children, and loop over them... | ||||||||||||||
| 40 | 4 | ELEMENT_LOOP: for my $element ($node->children->flatten) { | |||||||||||||
| 41 | |||||||||||||||
| 42 | 22 | ▶ | do { push @elements, $element; next ELEMENT_LOOP } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | unless $element->does('Pod::Elemental::Command'); | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 20 | ▶ | if ($element->does('Pod::Elemental::Command')) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | |||||||||||||||
| 47 | 20 | my $command = $element->command; | |||||||||||||
| 48 | 20 | ▶ | next ELEMENT_LOOP if $drop{$command}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | 12 | ▶ | if ($command eq 'item') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | |||||||||||||||
| 52 | 12 | my $content = $element->content; | |||||||||||||
| 53 | |||||||||||||||
| 54 | ### $content | ||||||||||||||
| 55 | 12 | ▶ | if ($content =~ /^\*\s*$/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | warn 'not handling plain * items yet'; | |||||||||||||
| 58 | 0 | next ELEMENT_LOOP; | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | elsif ($content =~ /^\*/) { | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 6 | $content =~ s/^\*\s*//; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 12 | chomp $content; | |||||||||||||
| 66 | 12 | $element->command($self->command); | |||||||||||||
| 67 | 12 | $element->content($content); | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 12 | push @elements, $element; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | } | ||||||||||||||
| 73 | |||||||||||||||
| 74 | 4 | $node->children([ @elements ]); | |||||||||||||
| 75 | 4 | return; | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 79 | |||||||||||||||
| 80 | 2 | 1; | |||||||||||||
| 81 | |||||||||||||||
| 82 | |||||||||||||||
| 83 | |||||||||||||||
| 84 | =pod | ||||||||||||||
| 85 | |||||||||||||||
| 86 | =encoding utf-8 | ||||||||||||||
| 87 | |||||||||||||||
| 88 | =head1 NAME | ||||||||||||||
| 89 | |||||||||||||||
| 90 | Pod::Elemental::Transformer::List::Converter - Convert a list to... something else | ||||||||||||||
| 91 | |||||||||||||||
| 92 | =head1 VERSION | ||||||||||||||
| 93 | |||||||||||||||
| 94 | This document describes 0.001 of Pod::Elemental::Transformer::List::Converter - released February 27, 2012 as part of Pod-Elemental-Transformer-List-Converter. | ||||||||||||||
| 95 | |||||||||||||||
| 96 | =head1 SYNOPSIS | ||||||||||||||
| 97 | |||||||||||||||
| 98 | # somewhere inside your code... | ||||||||||||||
| 99 | my $transformer = Pod::Elemental::Transformer::List::Converter->new; | ||||||||||||||
| 100 | $transformer->transform_node($node); | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =head1 DESCRIPTION | ||||||||||||||
| 103 | |||||||||||||||
| 104 | This L<Pod::Elemental::Transformer> takes a given node's children, and | ||||||||||||||
| 105 | converts any list commands to another command, C<head2> by default. | ||||||||||||||
| 106 | |||||||||||||||
| 107 | That is: | ||||||||||||||
| 108 | |||||||||||||||
| 109 | =over 4 | ||||||||||||||
| 110 | |||||||||||||||
| 111 | =item C<=item> becomes C<=head2>, and | ||||||||||||||
| 112 | |||||||||||||||
| 113 | =item C<=over> and <=back> commands are dropped entirely. | ||||||||||||||
| 114 | |||||||||||||||
| 115 | =back | ||||||||||||||
| 116 | |||||||||||||||
| 117 | As you can imagine, it's important to be selective with the nodes you run | ||||||||||||||
| 118 | through this transformer -- if you pass the entire document to it, it will | ||||||||||||||
| 119 | obliterate any lists found. | ||||||||||||||
| 120 | |||||||||||||||
| 121 | =head1 ATTRIBUTES | ||||||||||||||
| 122 | |||||||||||||||
| 123 | =head2 command | ||||||||||||||
| 124 | |||||||||||||||
| 125 | The command we change C<=item> elements to; defaults to C<head2>. | ||||||||||||||
| 126 | |||||||||||||||
| 127 | =head1 METHODS | ||||||||||||||
| 128 | |||||||||||||||
| 129 | =head2 command | ||||||||||||||
| 130 | |||||||||||||||
| 131 | Accessor to the command attribute. | ||||||||||||||
| 132 | |||||||||||||||
| 133 | =head2 transform_node($node) | ||||||||||||||
| 134 | |||||||||||||||
| 135 | Takes a node, and replaces any C<=item>'s with our target command (by default, | ||||||||||||||
| 136 | C<=head2>). We also drop any command elements found for C<=over> and | ||||||||||||||
| 137 | C<=back>. | ||||||||||||||
| 138 | |||||||||||||||
| 139 | =head1 SEE ALSO | ||||||||||||||
| 140 | |||||||||||||||
| 141 | Please see those modules/websites for more information related to this module. | ||||||||||||||
| 142 | |||||||||||||||
| 143 | =over 4 | ||||||||||||||
| 144 | |||||||||||||||
| 145 | =item * | ||||||||||||||
| 146 | |||||||||||||||
| 147 | L<Pod::Elemental::Transformer> | ||||||||||||||
| 148 | |||||||||||||||
| 149 | =item * | ||||||||||||||
| 150 | |||||||||||||||
| 151 | L<Pod::Weaver::Section::Collect::FromOther> | ||||||||||||||
| 152 | |||||||||||||||
| 153 | =back | ||||||||||||||
| 154 | |||||||||||||||
| 155 | =head1 SOURCE | ||||||||||||||
| 156 | |||||||||||||||
| 157 | The development version is on github at L<http://github.com/RsrchBoy/pod-elemental-transformer-list-converter> | ||||||||||||||
| 158 | and may be cloned from L<git://github.com/RsrchBoy/pod-elemental-transformer-list-converter.git> | ||||||||||||||
| 159 | |||||||||||||||
| 160 | =head1 BUGS | ||||||||||||||
| 161 | |||||||||||||||
| 162 | Please report any bugs or feature requests on the bugtracker website | ||||||||||||||
| 163 | https://github.com/RsrchBoy/pod-elemental-transformer-list-converter/issues | ||||||||||||||
| 164 | |||||||||||||||
| 165 | When submitting a bug or request, please include a test-file or a | ||||||||||||||
| 166 | patch to an existing test-file that illustrates the bug or desired | ||||||||||||||
| 167 | feature. | ||||||||||||||
| 168 | |||||||||||||||
| 169 | =head1 AUTHOR | ||||||||||||||
| 170 | |||||||||||||||
| 171 | Chris Weyl <cweyl@alumni.drew.edu> | ||||||||||||||
| 172 | |||||||||||||||
| 173 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 174 | |||||||||||||||
| 175 | This software is Copyright (c) 2012 by Chris Weyl. | ||||||||||||||
| 176 | |||||||||||||||
| 177 | This is free software, licensed under: | ||||||||||||||
| 178 | |||||||||||||||
| 179 | The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||
| 180 | |||||||||||||||
| 181 | =cut | ||||||||||||||
| 182 | |||||||||||||||
| 183 | |||||||||||||||
| 184 | __END__ | ||||||||||||||