| 1 | package Pod::Elemental::Element::Pod5::Region 0.103006; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: a region of Pod (this role likely to be removed) | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | with qw( | |||||||||||||||||||||||||||
| 6 | Pod::Elemental::Paragraph | ||||||||||||||||||||||||||||
| 7 | Pod::Elemental::Node | ||||||||||||||||||||||||||||
| 8 | Pod::Elemental::Command | ||||||||||||||||||||||||||||
| 9 | ); | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | #pod =head1 WARNING | ||||||||||||||||||||||||||||
| 12 | #pod | ||||||||||||||||||||||||||||
| 13 | #pod This class is somewhat sketchy and may be refactored somewhat in the future, | ||||||||||||||||||||||||||||
| 14 | #pod specifically to refactor its similarities to | ||||||||||||||||||||||||||||
| 15 | #pod L<Pod::Elemental::Element::Nested>. | ||||||||||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||||||||||
| 17 | #pod =head1 OVERVIEW | ||||||||||||||||||||||||||||
| 18 | #pod | ||||||||||||||||||||||||||||
| 19 | #pod A Pod5::Region element represents a region marked by a C<=for> command or a | ||||||||||||||||||||||||||||
| 20 | #pod pair of C<=begin> and C<=end> commands. It may have content of its own as well | ||||||||||||||||||||||||||||
| 21 | #pod as child paragraphs. | ||||||||||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||||||||||
| 23 | #pod Its C<as_pod_string> method will emit either a C<=begin/=end>-enclosed string | ||||||||||||||||||||||||||||
| 24 | #pod or a C<=for> command, based on whichever is permissible. | ||||||||||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||||||||||
| 26 | #pod =cut | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 11 | ▶ | use Pod::Elemental::Types qw(FormatName); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 11 | ▶ | use MooseX::Types::Moose qw(Bool); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | #pod =attr format_name | ||||||||||||||||||||||||||||
| 32 | #pod | ||||||||||||||||||||||||||||
| 33 | #pod This is the format to which the region was targeted. | ||||||||||||||||||||||||||||
| 34 | #pod | ||||||||||||||||||||||||||||
| 35 | #pod B<Note!> The format name should I<not> include the leading colon to indicate a | ||||||||||||||||||||||||||||
| 36 | #pod pod paragraph. For that, see C<L</is_pod>>. | ||||||||||||||||||||||||||||
| 37 | #pod | ||||||||||||||||||||||||||||
| 38 | #pod =cut | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 11 | has format_name => (is => 'ro', isa => FormatName, required => 1); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | #pod =attr is_pod | ||||||||||||||||||||||||||||
| 43 | #pod | ||||||||||||||||||||||||||||
| 44 | #pod If true, this region contains pod (ordinary or verbatim) paragraphs, as opposed | ||||||||||||||||||||||||||||
| 45 | #pod to data paragraphs. This will generally result from the document originating | ||||||||||||||||||||||||||||
| 46 | #pod in a C<=begin> block with a colon-prefixed target identifier: | ||||||||||||||||||||||||||||
| 47 | #pod | ||||||||||||||||||||||||||||
| 48 | #pod =begin :html | ||||||||||||||||||||||||||||
| 49 | #pod | ||||||||||||||||||||||||||||
| 50 | #pod This is still a verbatim paragraph. | ||||||||||||||||||||||||||||
| 51 | #pod | ||||||||||||||||||||||||||||
| 52 | #pod =end :html | ||||||||||||||||||||||||||||
| 53 | #pod | ||||||||||||||||||||||||||||
| 54 | #pod =cut | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 11 | has is_pod => (is => 'ro', isa => Bool, required => 1, default => 1); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 10 | ▶ | sub command { 'begin' } | ||||||||||||||||||||||||||
|
Subroutine
command: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 9 | ▶ | sub closing_command { 'end' } | ||||||||||||||||||||||||||
|
Subroutine
closing_command: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 10 | ▶ | sub _display_as_for { | ||||||||||||||||||||||||||
|
Subroutine
_display_as_for: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||
| 62 | 10 | my ($self) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # Everything after "=for target" becomes the lone child paragraph, so there | ||||||||||||||||||||||||||||
| 65 | # is nowhere to put the (technically illegal) content. -- rjbs, 2009-11-24 | ||||||||||||||||||||||||||||
| 66 | 10 | ▶ | return if $self->content =~ /\S/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # We can't have more than one paragraph, because there'd be a blank, so we | ||||||||||||||||||||||||||||
| 69 | # couldn't round trip. -- rjbs, 2009-11-24 | ||||||||||||||||||||||||||||
| 70 | 8 | ▶ | return if @{ $self->children } != 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 4 | my $child = $self->children->[0]; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | ▶ | return if $child->content =~ m{^\s*$}m; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | my $base = 'Pod::Elemental::Element::Pod5::'; | |||||||||||||||||||||||||||
| 77 | 2 | ▶ | return 1 if $self->is_pod and $child->isa("${base}Ordinary"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->is_pod and $child->isa("${base}Ordinary")
MC/DC50%1/2
$self->is_pod and $child->isa("${base}Ordinary")
$self->is_pod
$child->isa("${base}Ordinary")
Truth table66%2/3
A and B
A= $self->is_podB= $child->isa("${base}Ordinary")
| |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | return 1 if ! $self->is_pod and $child->isa("${base}Data"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $self->is_pod and $child->isa("${base}Data")
MC/DC0%0/2
not $self->is_pod and $child->isa("${base}Data")
not $self->is_pod
$child->isa("${base}Data")
Truth table33%1/3
not(A) and B
A= not $self->is_podB= $child->isa("${base}Data")
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | return; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 10 | ▶ | sub as_pod_string { | ||||||||||||||||||||||||||
|
Subroutine
as_pod_string: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 84 | 10 | my ($self) = @_; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 10 | my $string; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 10 | ▶ | if ($self->_display_as_for) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 1 | $string = $self->__as_pod_string_for($self); | |||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||
| 91 | 9 | $string = $self->__as_pod_string_begin($self); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 10 | $string =~ s/\n*\z//g; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 10 | return $string; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 9 | ▶ | sub __as_pod_string_begin { | ||||||||||||||||||||||||||
|
Subroutine
__as_pod_string_begin: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 100 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 9 | my $content = $self->content; | |||||||||||||||||||||||||||
| 103 | 9 | ▶ | my $colon = $self->is_pod ? ':' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 9 | ▶ | my $string = sprintf "=%s %s%s\n", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | $self->command, | ||||||||||||||||||||||||||||
| 107 | $colon . $self->format_name, | ||||||||||||||||||||||||||||
| 108 | ($content =~ /\S/ ? " $content\n" : "\n"); | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 9 | $string .= join(q{}, map { $_->as_pod_string } @{ $self->children }); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | $string .= "\n\n" | ||||||||||||||||||||||||||||
| 113 | 9 | ▶ | if @{ $self->children } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$self->children;} and $self->children->[-1]->isa("Pod::Elemental::Element::Pod5::Data")
MC/DC100%2/2
@{$self->children;} and $self->children->[-1]->isa("Pod::Elemental::Element::Pod5::Data")
@{$self->children;}
$self->children->[-1]->isa("Pod::Elemental::Element::Pod5::Data")
Truth table100%3/3
A and B
A= @{$self->children;}B= $self->children->[-1]->isa("Pod::Elemental::Element::Pod5::Data")
| |||||||||||||||||||||||||||||
| 114 | and $self->children->[-1]->isa( 'Pod::Elemental::Element::Pod5::Data'); | ||||||||||||||||||||||||||||
| 115 | # Pod5::$self->is_pod; # XXX: HACK!! -- rjbs, 2009-10-21 | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 9 | $string .= sprintf "=%s %s", | |||||||||||||||||||||||||||
| 118 | $self->closing_command, | ||||||||||||||||||||||||||||
| 119 | $colon . $self->format_name; | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 9 | return $string; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | ▶ | sub __as_pod_string_for { | ||||||||||||||||||||||||||
|
Subroutine
__as_pod_string_for: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 125 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | my $content = $self->content; | |||||||||||||||||||||||||||
| 128 | 1 | ▶ | my $colon = $self->is_pod ? ':' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 1 | my $string = sprintf "=for %s %s", | |||||||||||||||||||||||||||
| 131 | $colon . $self->format_name, | ||||||||||||||||||||||||||||
| 132 | $self->children->[0]->as_pod_string; | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 1 | return $string; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub as_debug_string { | ||||||||||||||||||||||||||
|
Subroutine
as_debug_string: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 138 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | my $colon = $self->is_pod ? ':' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | my $string = sprintf "=%s %s", | |||||||||||||||||||||||||||
| 143 | $self->command, | ||||||||||||||||||||||||||||
| 144 | $colon . $self->format_name; | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | return $string; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 11 | with 'Pod::Elemental::Autoblank'; | |||||||||||||||||||||||||||
| 150 | 11 | with 'Pod::Elemental::Autochomp'; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # BEGIN Autochomp Replacement | ||||||||||||||||||||||||||||
| 153 | 11 | ▶ | use Pod::Elemental::Types qw(ChompedString); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 154 | 11 | has '+content' => (coerce => 1, isa => ChompedString); | |||||||||||||||||||||||||||
| 155 | # END Autochomp Replacement | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 11 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 158 | 11 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 159 | 11 | 1; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | __END__ | ||||||||||||||||||||||||||||