| 1 | package Data::Org::Template; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Iterator::Simple; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | Data::Org::Template - template engine that plays well with iterators | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | Version 0.04 | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | =head1 CREATING A TEMPLATE | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =head2 new (text, [start, end]) | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | Aside from the text to be loaded as a template, you can also provide delimiters for the fields in C<start> and C<end>. If only one string is provided, it is assumed to encode | ||||||||||||||||||||||||||||||||||||||||||
| 32 | both start *and* end, and will be split in equal halves. The default delimiters are C<[[> and C<]]>. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # [< template_test2|parse_template] | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 26 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 26 | my ($class, $text, $start, $end) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 26 | my $self = bless ({}, $class); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 26 | ▶ | if (ref($text) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | $self->{template} = $text; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 25 | $self->{template} = _parse_template ($text, $start, $end); | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 26 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 25 | ▶ | sub _parse_template { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_template: called CC=23 SCAR=31.4
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 25 | my ($text, $start, $end) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 25 | ▶ | if (not defined $end) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 24 | ▶ | if (not defined $start) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 20 | $start = '[['; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 20 | $end = ']]'; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | ▶ | if (length ($start) % 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | croak "unmatched template field delimiters $start"; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | $end = substr($start, length($start)/2); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | $start = substr($start, 0, length($start)/2); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 25 | my $template = []; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 25 | my @pieces = _split_template ($text, $start, $end); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 25 | my @stack = ([0, $template]); # 2018-09-08 the stack for pushing section directives | |||||||||||||||||||||||||||||||||||||||||
| 70 | 25 | my $swallow_nl = 0; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 25 | ▶ | while (@pieces) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 125 | my $piece = shift(@pieces); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 125 | my ($type, $what) = @$piece; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 125 | ▶ | if ($type) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 55 | ▶ | if ($what eq '.' or $what =~ /^\.\|/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$what eq "." or $what =~ /^\.\|/
MC/DC100%2/2
$what eq "." or $what =~ /^\.\|/
$what eq "."
$what =~ /^\.\|/
Truth table100%3/3
A or B
A= $what eq "."B= $what =~ /^\.\|/
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | push @$template, ['?', $what]; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | elsif ($what =~ /^\./) { # 2018-09-08 section/subsection tag | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 23 | $swallow_nl = 1; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 23 | ▶ | if ($what eq '..') { # section end | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 8 | ▶ | shift @stack if ($stack[0]->[0]); # Pop top of stack if it's a subsection. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 8 | ▶ | shift @stack unless scalar (@stack) < 2; # .. pops the stack unless the stack is already at the top | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 8 | $template = $stack[0]->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } elsif ($what =~ /^\.\./) { # new subsection | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | ▶ | shift @stack if ($stack[0]->[0]); # Subsections can't nest. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | my $section = $stack[0]->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | $what =~ s/^\.\.//; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 7 | my ($tag, $parm) = split " ", $what, 2; | |||||||||||||||||||||||||||||||||||||||||
| 89 | #my $section = node_add_child ($template, defined $parm ? node_from_string ("$tag: " . '"' . quote_escape($parm) . '"') | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # : node_from_string ($tag)); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 7 | my $subsection = [$tag, $parm, []]; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 7 | $section->[2]->{$tag} = $subsection; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 7 | unshift @stack, [1, $subsection]; | |||||||||||||||||||||||||||||||||||||||||
| 94 | #$template = $section; | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 7 | $template = $subsection->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } else { # top-level section start | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | $what =~ s/^\.//; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | my ($tag, $parm) = split " ", $what, 2; | |||||||||||||||||||||||||||||||||||||||||
| 99 | #my $section = node_add_child ($template, defined $parm ? node_from_string ("$tag: " . '"' . quote_escape($parm) . '"') | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # : node_from_string ($tag)); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 8 | my $subsection = ['.', undef, []]; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 8 | my $section = [$tag, $parm, { '.' => $subsection}]; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 8 | push @$template, $section; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 8 | unshift @stack, [0, $section]; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 8 | unshift @stack, [1, $subsection]; | |||||||||||||||||||||||||||||||||||||||||
| 106 | #$template = $section; | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 8 | $template = $subsection->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } elsif ($what =~ /^!/) { # 2018-09-09 banged directive | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 5 | $swallow_nl = 1; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | $what =~ s/^!//; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 5 | my ($tag, $parm) = split " ", $what, 2; | |||||||||||||||||||||||||||||||||||||||||
| 113 | #node_add_child ($template, defined $parm ? node_from_string ("$tag: " . '"' . quote_escape($parm) . '"') | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # : node_from_string ($tag)); | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 5 | ▶ | push @$template, defined $parm ? [$tag, $parm] : [$tag]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | #node_add_child ($template, node_from_string ("insert_value: $what")); | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 25 | push @$template, ['?', $what]; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | } else { # If there's anything after us, we can't emit a carriage return at the end. | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 70 | my @lines = split /^/, $what; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 70 | ▶ | while (scalar @lines and $lines[0] =~ /^ /) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @lines and $lines[0] =~ /^ /
MC/DC100%2/2
scalar @lines and $lines[0] =~ /^ /
scalar @lines
$lines[0] =~ /^ /
Truth table100%3/3
A and B
A= scalar @linesB= $lines[0] =~ /^ /
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | my $line = shift (@lines); | |||||||||||||||||||||||||||||||||||||||||
| 124 | #node_add_child ($template, node_from_string ('lit "' . quote_escape($line) . (scalar(@lines) ? '\n"' : '"'))); | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | ▶ | push @$template, ['lit', $line . (scalar(@lines) ? "\n" : '')]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | $swallow_nl = 0; # any output invalidates the swallow-nl flag | |||||||||||||||||||||||||||||||||||||||||
| 127 | } # Now we have no leading spaces. | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # We only care about the last line as a lit. This logic below is kind of weird because it evolved from | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # different assumptions (which were wrong). May need to rewrite. Maybe already did? | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 70 | ▶ | if (scalar @lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | # 2018-09-07 - yeah, it was wrong in the case that we have a newline followed immediately by a value field. | ||||||||||||||||||||||||||||||||||||||||||
| 132 | #my $last_line = pop(@lines); | ||||||||||||||||||||||||||||||||||||||||||
| 133 | #node_add_child ($template, tagless_text (join ("", @lines))) if scalar @lines; | ||||||||||||||||||||||||||||||||||||||||||
| 134 | #node_add_child ($template, node_from_string ('lit "' . quote_escape($last_line) . '"')); | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 67 | foreach my $line (@lines) { # 2018-09-07 - just output everything as a lit instead of screwing around with tagless text, which has syntactic issues anyway. | |||||||||||||||||||||||||||||||||||||||||
| 136 | 89 | ▶ | if ($swallow_nl and $line eq "\n") { # 2018-09-08 - swallow linefeed after section directive if there's no additional text on that line. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$swallow_nl and $line eq "\n"
MC/DC100%2/2
$swallow_nl and $line eq "\n"
$swallow_nl
$line eq "\n"
Truth table100%3/3
A and B
A= $swallow_nlB= $line eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | #node_add_child ($template, node_from_string ('lit "' . quote_escape($line) . '"')); | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 68 | push @$template, ['lit', $line]; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 89 | $swallow_nl = 0; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 25 | $stack[0]->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 50 | ▶ | sub _regexp_escape { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_regexp_escape: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 50 | my $re = shift; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 50 | $re =~ s/([.\^*+?()[{\\|*])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 50 | return $re; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 25 | ▶ | sub _split_template { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_template: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 25 | my ($text, $start, $end) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 25 | $start = _regexp_escape ($start); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 25 | $end = _regexp_escape ($end); | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 25 | my @out = (); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 25 | foreach my $bit (split (/($start.+?$end)/, $text)) { | |||||||||||||||||||||||||||||||||||||||||
| 163 | 133 | ▶ | if ($bit =~ /$start(.*)$end/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 55 | push @out, [1, $1]; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 78 | ▶ | push @out, [0, $bit] unless $bit eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 25 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | =head1 EXPRESSING A TEMPLATE | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | A template can be either fully or partly expressed. If it's only partly expressed, the result is a new template with some of the | ||||||||||||||||||||||||||||||||||||||||||
| 175 | fields replaced with values, and others left intact. | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | If the template uses transducers we don't recognize, it will croak with an appropriate warning. | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | =head2 iter([data getter]) | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | Starts a token iterator from the template. A token stream, the way I do it, is an iterator for which each value returned is either | ||||||||||||||||||||||||||||||||||||||||||
| 182 | a string (plain text) or a token. A token is an arrayref of [type, value, <arbitrary stuff>], so extracting the value is easy. | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | If no data getter is specified, uses the one registered in the template. If none is registered, croaks because you can't express a template on nothing, can you? | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 21 | ▶ | sub iter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iter: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 21 | my $context = undef; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 21 | ▶ | if (scalar @_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 5 | $context = [@_]; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 21 | my $data_getter = $self->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 21 | ▶ | $data_getter = Data::Org::Template::Getter->new ({}) unless defined $data_getter; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 21 | ▶ | if (not defined $self->{transducer}) { # Here, do some error checking once we have a transducer scan working. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | $self->{transducer} = { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 14 | ':' => \&Data::Org::Template::Transducer::text::tt, | |||||||||||||||||||||||||||||||||||||||||
| 201 | 'nl' => \&Data::Org::Template::Transducer::nl::tt, | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 'lit' => \&Data::Org::Template::Transducer::lit::tt, | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 'if' => \&Data::Org::Template::Transducer::if::tt, | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 'with' => \&Data::Org::Template::Transducer::with::tt, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 'list' => \&Data::Org::Template::Transducer::list::tt, | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 'else' => 'ignore', | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 'alt' => 'ignore', | ||||||||||||||||||||||||||||||||||||||||||
| 208 | '?' => \&Data::Org::Template::Transducer::value::tt, | ||||||||||||||||||||||||||||||||||||||||||
| 209 | '*undefined*' => 'ignore', | ||||||||||||||||||||||||||||||||||||||||||
| 210 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 21 | my $tags = $self->transducers_requested(); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 21 | foreach my $tag (@$tags) { | |||||||||||||||||||||||||||||||||||||||||
| 214 | 49 | ▶ | croak ("Unknown transducer '$tag' used in template") unless $self->{transducer}->{$tag}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 20 | _express_template ($self->{template}, $data_getter, $context, 0, $self->{transducer}); | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 34 | ▶ | sub _express_template { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_express_template: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 34 | my ($template, $data_getter, $context, $indent, $transducer) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 34 | ▶ | $indent = 0 unless defined $indent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 34 | my @line_queue = (); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 34 | my @token_queue = (); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 34 | my $substream; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 34 | my $local_indent = 0; # The indent is how many spaces we have to insert after each line break; | |||||||||||||||||||||||||||||||||||||||||
| 230 | # the local indent is how many *more* spaces a child would have to indent at the current position. | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 34 | my $needs_indent = 0; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 34 | my @child_queue = (@$template); # Take a copy of the template for processing. | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 155 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=28.5
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 155 | ▶ | if (scalar @line_queue) { # If lines are queued from the last token, return a line | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $this_indent = $indent+$local_indent; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if (scalar @line_queue == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $local_indent = length($line_queue[0]); | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | return (' ' x $this_indent) . shift (@line_queue); # 2018-09-14 - I'm not convinced by this logic. I really need to do some additional testing of indentation. | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | SUBSTREAM: | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 246 | ▶ | if (defined $substream) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 212 | my $token = $substream->(); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 212 | ▶ | if (defined $token) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 121 | my $val = $token; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 121 | ▶ | if (ref $token) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 39 | ▶ | return $token if $token->[0] eq '"'; # Text to be passed through without examination (already indented properly) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $val = $token->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 82 | ▶ | if ($val eq "\n") { # 2018-09-14 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | # Tokens that are themselves simply a line end get passed through with their type. | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 7 | $local_indent = 0; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 7 | return $token; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } elsif ($val =~ /\n/) { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | # A token that *has* line breaks, though, can't stay a token because we may have to indent it. | ||||||||||||||||||||||||||||||||||||||||||
| 258 | # Split into lines and deal with it as plain text. | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 17 | @line_queue = split /^/, $val; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 17 | return shift (@line_queue); # Return first line right now | |||||||||||||||||||||||||||||||||||||||||
| 261 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # No line breaks means we just increment our local indent, then emit this token | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 58 | $local_indent += length($val); | |||||||||||||||||||||||||||||||||||||||||
| 264 | 58 | return $token; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 91 | $substream = undef; | |||||||||||||||||||||||||||||||||||||||||
| 268 | # fall through to next child for another substream if this one is exhausted | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | NEXT_CHILD: | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 125 | ▶ | if (scalar @child_queue) { # Is there still template to be expressed? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 91 | my $child = shift (@child_queue); | |||||||||||||||||||||||||||||||||||||||||
| 274 | 91 | my $lookup = $child->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 91 | ▶ | $lookup = ':' if not $lookup; # Tagless text (not actually needed with this AST, but still) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 91 | my $tt = $transducer->{$lookup}; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 91 | ▶ | if (not defined $tt) { # Do we keep this? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $tt = $transducer->{'*undefined*'}; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 91 | ▶ | if (not defined $tt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | croak ("undefined transducer $tt encountered in template"); | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 91 | ▶ | goto NEXT_CHILD unless ref $tt; # Skip any "ignore" tags we've explicitly identified | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 91 | $substream = $tt->($child, $data_getter, $context, $indent + $local_indent, $transducer); | |||||||||||||||||||||||||||||||||||||||||
| 285 | 91 | goto SUBSTREAM; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 34 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 34 | } | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | =head2 _compile_token_stream ($stream) | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | This is just a helper function - NOT object-oriented in nature (the initial underscore might help you - and me - remember that). | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 20 | ▶ | sub _compile_token_stream { # 2018-09-13 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile_token_stream: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 20 | my $stream = shift; | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 20 | my $output = ''; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 20 | my $tok; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 20 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 303 | 102 | $tok = $stream->(); | |||||||||||||||||||||||||||||||||||||||||
| 304 | 102 | ▶ | return $output unless defined $tok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 82 | ▶ | if (not ref $tok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 43 | $output .= $tok; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 39 | $output .= $tok->[1]; # A non-string token is an arrayref with a type, the string content, and arbitrary additional data | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | =head2 text() | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | Compiles the iterator into an output string for you, using C<_compile_token_stream>. | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 21 | ▶ | sub text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 21 | _compile_token_stream ($self->iter (@_)); | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | # Token stream manipulators. | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 5 | ▶ | sub quote_substream { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quote_substream: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 5 | my $stream = shift; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 15 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 15 | my $v = $stream->(); | |||||||||||||||||||||||||||||||||||||||||
| 329 | 15 | ▶ | return $v if not defined $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 10 | ▶ | return $v if ref $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 10 | return ['"', $v]; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 5 | } | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | sub undef_stream { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
undef_stream: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | sub { return undef }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | =head1 REGISTERING A DATA GETTER | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | A template can be expressed by providing a data getter (a map from name to value) at expression time, but you can also register a default data getter against | ||||||||||||||||||||||||||||||||||||||||||
| 341 | the template when you define it, for convenience. | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | =head2 data_getter ([data getter]) | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | Sets or gets the current data getter for the template. If you pass one or more data getters (which can be a data getter object, a hashref, or an arrayref of other | ||||||||||||||||||||||||||||||||||||||||||
| 348 | data getters) then each will be checked in sequence. | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 14 | ▶ | sub data_getter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data_getter: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 14 | ▶ | return $self->{data} unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 14 | ▶ | if (scalar @_ eq 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 13 | $self->{data} = Data::Org::Template::Getter->new ($_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 357 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | $self->{data} = Data::Org::Template::Getter->new ([@_]); | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 14 | $self->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | #=head2 check_data_requested () | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # Checks the data requested against the current data getter, if any. Returns a list of values I<not> available in the getter. | ||||||||||||||||||||||||||||||||||||||||||
| 365 | #=cut | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | # -------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 369 | # Working with custom transducers, only sketched out | ||||||||||||||||||||||||||||||||||||||||||
| 370 | # -------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 371 | #=head2 data_requested () -- this is yet to come | ||||||||||||||||||||||||||||||||||||||||||
| 372 | # | ||||||||||||||||||||||||||||||||||||||||||
| 373 | #=cut | ||||||||||||||||||||||||||||||||||||||||||
| 374 | # | ||||||||||||||||||||||||||||||||||||||||||
| 375 | #=head2 transducers_requested () | ||||||||||||||||||||||||||||||||||||||||||
| 376 | # | ||||||||||||||||||||||||||||||||||||||||||
| 377 | #This provides a list of the transducers used in the template. It's really only of use if you're using custom transducers. | ||||||||||||||||||||||||||||||||||||||||||
| 378 | # | ||||||||||||||||||||||||||||||||||||||||||
| 379 | #=cut | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | # This will really only come in handy once I have a need for custom transducers; it's left over from an earlier prototype where I was playing with exactly that. | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 25 | ▶ | sub transducers_requested { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transducers_requested: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 25 | my $bag = {}; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 25 | _list_transducers ($self->{template}, $bag); | |||||||||||||||||||||||||||||||||||||||||
| 386 | 25 | my @list = sort {$a cmp $b} keys %$bag; | |||||||||||||||||||||||||||||||||||||||||
| 387 | 25 | \@list; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 51 | ▶ | sub _list_transducers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list_transducers: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 51 | my ($template, $bag) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 51 | foreach my $item (@$template) { | |||||||||||||||||||||||||||||||||||||||||
| 392 | 116 | $bag->{$item->[0]} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 116 | ▶ | if (scalar @$item > 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 14 | ▶ | while (my ($k, $v) = each (%{$item->[2]})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 26 | _list_transducers ($v->[2], $bag); | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | #=head2 register_transducer () | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # | ||||||||||||||||||||||||||||||||||||||||||
| 403 | #=cut | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | # ----------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 409 | # Default getter: Data::Org::Template::Getter | ||||||||||||||||||||||||||||||||||||||||||
| 410 | # ----------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | package Data::Org::Template::Getter; | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 5 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 5 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 19 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 19 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 19 | ▶ | if (scalar @_ eq 1) { # If there's a single input and that input is already capable of acting like a getter, don't instantiate anything, just use it. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 19 | my ($candidate) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 19 | ▶ | if (blessed($candidate) && $candidate->can('get') && $candidate->can('get_iterated')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
builtin::blessed($candidate) and $candidate->can("get") and $candidate->can("get_iterated")
builtin::blessed($candidate) and $candidate->can("get")
MC/DC0%0/3
builtin::blessed($candidate) and $candidate->can("get") and $candidate->can("get_iterated")
builtin::blessed($candidate)
$candidate->can("get")
$candidate->can("get_iterated")
Truth table25%1/4
A and B and C
A= builtin::blessed($candidate)B= $candidate->can("get")C= $candidate->can("get_iterated")
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | return $candidate; | |||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 19 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 19 | $self->{source} = [@_]; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 19 | $self->{formatter} = Data::Org::Template::Formatter->new(); | |||||||||||||||||||||||||||||||||||||||||
| 428 | 19 | $self->{format} = $self->{formatter}->formatter; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 19 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | sub new_raw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_raw: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | $self->{source} = [@_]; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $self->{formatter} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | $self->{format} = sub { return $_[0]; }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | sub formatter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
formatter: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my $formatter = shift; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if (defined $formatter) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $self->{formatter} = $formatter; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $self->{format} = $self->{formatter}->formatter; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $self->{formatter}; | |||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 47 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 47 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 47 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 47 | ▶ | return unless defined $what; # Should this croak? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 47 | ▶ | my $context = shift || $self->{source}; # A list of data packets in order of search; the first may be a scalar when we're in a list context. | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self->{'source'}
MC/DC0%0/2
shift() || $self->{'source'}
shift()
$self->{'source'}
Truth table66%2/3
A || B
A= shift()B= $self->{'source'}
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 47 | my @formatters; | |||||||||||||||||||||||||||||||||||||||||
| 457 | 47 | ($what, @formatters) = $self->{format}->($what); | |||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 47 | my $value = $self->_get($what, $context); | |||||||||||||||||||||||||||||||||||||||||
| 460 | 47 | ▶ | while (defined $value and ref ($value) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value and ref $value eq "CODE"
MC/DC100%2/2
defined $value and ref $value eq "CODE"
defined $value
ref $value eq "CODE"
Truth table100%3/3
A and B
A= defined $valueB= ref $value eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 2 | $value = $value->(); | |||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 47 | foreach my $f (@formatters) { | |||||||||||||||||||||||||||||||||||||||||
| 465 | 9 | $value = $f->($value); | |||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 47 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 53 | ▶ | sub _get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get: called CC=10 SCAR=23.6
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 53 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 472 | 53 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 53 | my $context = shift; | |||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 53 | ▶ | return $context->[0] if $what eq '.'; # Special case for a list context. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 45 | foreach my $source (@$context) { | |||||||||||||||||||||||||||||||||||||||||
| 478 | 54 | ▶ | $source = $self->{source} if $source eq '*'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 54 | ▶ | next unless ref $source; # Just in case we're in a list and the first "source" is a scalar value. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 49 | my $maybe; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 49 | ▶ | if (blessed($source)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | $maybe = $source->get ($what); | |||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | return $maybe if defined $maybe; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 49 | ▶ | if (ref($source) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 6 | $maybe = $self->_get ($what, $source); | |||||||||||||||||||||||||||||||||||||||||
| 490 | 6 | ▶ | return $maybe if defined $maybe; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | next; # Here's a subtle error - leave this out. This surprised me. | |||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | # Must be a hash, then. | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 43 | ▶ | return $source->{$what} if defined $source->{$what}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 5 | ▶ | sub get_iterated { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_iterated: called CC=11 SCAR=27.8
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 502 | 5 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 5 | ▶ | my $context = shift || $self->{source}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->{'source'}
MC/DC0%0/2
shift() || $self->{'source'}
shift()
$self->{'source'}
Truth table33%1/3
A || B
A= shift()B= $self->{'source'}
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 5 | my $src = $self->get ($what, $context); | |||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 5 | ▶ | return if not defined $src; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | # If this is a scalar, "iterate" over that single value. | ||||||||||||||||||||||||||||||||||||||||||
| 509 | 4 | my $r = ref($src); | |||||||||||||||||||||||||||||||||||||||||
| 510 | 4 | ▶ | if (not $r) { # -> new subcontext is an iterator that will return a single subframe, consisting of a hash frame and the existing context as a backup | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | my $done = 0; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | return undef if $done; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | $done = 1; | |||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | return [{'.' => $src}, {_total => 1, _count => 0}, @$context]; | |||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 518 | # If a hash, iterate over the hash as a single child frame. | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 4 | ▶ | if ($r eq 'HASH') { # -> new subcontext is an iterator that will return a single subframe | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | return unless scalar keys (%$src); # An empty hash is equivalent to no data found | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my $done = 0; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | return undef if $done; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | $done = 1; | |||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | return [$src, {_total => 1, _count => 0}, @$context]; | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 528 | # If a list, it's obvious. | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 4 | ▶ | if ($r eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | 2 | ▶ | return unless scalar $src; # An empty list is equivalent to no data found | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 2 | my @queue = @$src; | |||||||||||||||||||||||||||||||||||||||||
| 532 | 2 | my $total = scalar @queue; | |||||||||||||||||||||||||||||||||||||||||
| 533 | 2 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 534 | 2 | my $query_info = { | |||||||||||||||||||||||||||||||||||||||||
| 535 | _total => $total, | ||||||||||||||||||||||||||||||||||||||||||
| 536 | _count => $count, | ||||||||||||||||||||||||||||||||||||||||||
| 537 | _remaining => $total | ||||||||||||||||||||||||||||||||||||||||||
| 538 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 8 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | 8 | ▶ | return undef unless scalar @queue; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 4 | $query_info->{_count} = $count; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 4 | $query_info->{_remaining} = $total - $count - 1; | |||||||||||||||||||||||||||||||||||||||||
| 544 | 4 | $count += 1; # For next time | |||||||||||||||||||||||||||||||||||||||||
| 545 | 4 | my $next = shift @queue; | |||||||||||||||||||||||||||||||||||||||||
| 546 | 4 | return [$next, $query_info, @$context]; | |||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 2 | } | |||||||||||||||||||||||||||||||||||||||||
| 549 | 2 | ▶ | if (blessed($src) && $src->can('iter_hash')) { # We have a record stream! | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($src) and $src->can("iter_hash")
MC/DC0%0/2
builtin::blessed($src) and $src->can("iter_hash")
builtin::blessed($src)
$src->can("iter_hash")
Truth table33%1/3
A and B
A= builtin::blessed($src)B= $src->can("iter_hash")
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 2 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 551 | 2 | my $query_info = { | |||||||||||||||||||||||||||||||||||||||||
| 552 | _count => $count, | ||||||||||||||||||||||||||||||||||||||||||
| 553 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 554 | 2 | my $iter = $src->iter_hash(); # Might think of ways to pass parameters at some point. | |||||||||||||||||||||||||||||||||||||||||
| 555 | 2 | my $next = $iter->(); | |||||||||||||||||||||||||||||||||||||||||
| 556 | 2 | ▶ | return unless $next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | 8 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 8 | ▶ | return unless $next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | 4 | $query_info->{_count} = $count; | |||||||||||||||||||||||||||||||||||||||||
| 561 | 4 | $count += 1; # For next time | |||||||||||||||||||||||||||||||||||||||||
| 562 | 4 | my $this = $next; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 4 | $next = $iter->(); | |||||||||||||||||||||||||||||||||||||||||
| 564 | 4 | return [$this, $query_info, @$context]; | |||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | 2 | } | |||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | # ----------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 570 | # Formatting framework | ||||||||||||||||||||||||||||||||||||||||||
| 571 | # ----------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | package Data::Org::Template::Formatter; | ||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | 19 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 19 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 577 | 19 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 578 | $self->{lookup} = { | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 9 | ▶ | html => sub { \&html_encode }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | 19 | }; | |||||||||||||||||||||||||||||||||||||||||
| 581 | 19 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | return unless defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my $formatter = shift; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | if (defined $formatter) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | $self->{lookup}->{$name} = $formatter; | |||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | $self->{lookup}->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 19 | ▶ | sub formatter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
formatter: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 19 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 597 | 47 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 47 | $self->parse(shift); | |||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 19 | } | |||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 47 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | 47 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 604 | 47 | my $spec = shift; | |||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | 47 | my @coderefs = (); | |||||||||||||||||||||||||||||||||||||||||
| 607 | 47 | ▶ | while ($spec =~ /(.*)\| *([[:alnum:]][[:alnum:] \-_.*\/\\]*)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 608 | 9 | my ($new_spec, $format) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 609 | 9 | $spec = $new_spec; | |||||||||||||||||||||||||||||||||||||||||
| 610 | 9 | $spec =~ s/ *$//; # Drop trailing spaces, if any | |||||||||||||||||||||||||||||||||||||||||
| 611 | 9 | push @coderefs, $self->make_formatter ($format); | |||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 47 | return ($spec, @coderefs); | |||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 9 | ▶ | sub make_formatter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_formatter: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 618 | 9 | my $format = shift; | |||||||||||||||||||||||||||||||||||||||||
| 619 | 9 | my $parm = ''; | |||||||||||||||||||||||||||||||||||||||||
| 620 | 9 | ▶ | if ($format =~ /^([[:alnum:]]+)(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | 9 | ($format, $parm) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||
| 623 | 9 | my $formatter = $self->{lookup}->{$format}; | |||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | return sub { $_[0] } unless defined $formatter; # Error handling might be nice here | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | 9 | return $formatter->($parm); | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | 9 | ▶ | sub html_encode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
html_encode: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | 9 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 630 | 9 | $str =~ s/&/&/g; | |||||||||||||||||||||||||||||||||||||||||
| 631 | 9 | $str =~ s/</</g; | |||||||||||||||||||||||||||||||||||||||||
| 632 | 9 | $str =~ s/>/>/g; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 9 | $str; | |||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | # ----------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 637 | # Standard transducers: text, nl, lit, value, if, with, and list. | ||||||||||||||||||||||||||||||||||||||||||
| 638 | # ----------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 639 | package Data::Org::Template::Transducer::text; | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | sub values { () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | ▶ | sub tt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tt: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | my $source = shift; | |||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | my $done = 0; | |||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | ▶ | return undef if $done; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | $done = 1; | |||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | return $source->[1] . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | package Data::Org::Template::Transducer::nl; | ||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | sub values { () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 656 | 1 | ▶ | sub tt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tt: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | 1 | my $done = 0; | |||||||||||||||||||||||||||||||||||||||||
| 658 | 2 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 2 | ▶ | return undef if $done; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | $done = 1; | |||||||||||||||||||||||||||||||||||||||||
| 661 | 1 | return "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | package Data::Org::Template::Transducer::lit; | ||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | sub values { () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 56 | ▶ | sub tt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tt: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | 56 | my $source = shift; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 56 | my $done = 0; | |||||||||||||||||||||||||||||||||||||||||
| 671 | 112 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 672 | 112 | ▶ | return undef if $done; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | 56 | $done = 1; | |||||||||||||||||||||||||||||||||||||||||
| 674 | 56 | return $source->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 56 | } | |||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | package Data::Org::Template::Transducer::value; | ||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | sub values { ($_[0]->[1]) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | 25 | ▶ | sub tt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tt: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 682 | 25 | my ($source, $data_getter, $context, $indent, $transducer) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 683 | 25 | my $value = $data_getter->get($source->[1], $context); | |||||||||||||||||||||||||||||||||||||||||
| 684 | 25 | my $done = 0; | |||||||||||||||||||||||||||||||||||||||||
| 685 | 50 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 50 | ▶ | return undef if $done; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | 25 | $done = 1; | |||||||||||||||||||||||||||||||||||||||||
| 688 | 25 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||
| 690 | 25 | } | |||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | package Data::Org::Template::Transducer::if; | ||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | sub values { () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 696 | 2 | ▶ | sub tt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tt: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 697 | 2 | my ($source, $data_getter, $context, $indent, $transducer) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | 2 | ▶ | if ($data_getter->get($source->[1], $context)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | 1 | return Data::Org::Template::quote_substream (Data::Org::Template::_express_template ($source->[2]->{'.'}->[2], $data_getter, $context, $indent, $transducer)); | |||||||||||||||||||||||||||||||||||||||||
| 701 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 702 | 1 | ▶ | if (exists $source->[2]->{'else'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | 1 | return Data::Org::Template::quote_substream (Data::Org::Template::_express_template ($source->[2]->{'else'}->[2], $data_getter, $context, $indent, $transducer)); | |||||||||||||||||||||||||||||||||||||||||
| 704 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | return Data::Org::Template::undef_stream(); | |||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | package Data::Org::Template::Transducer::with; | ||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | ▶ | sub values { () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 713 | 2 | ▶ | sub tt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tt: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | 2 | my ($source, $data_getter, $context, $indent, $transducer) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 715 | 2 | my $ctx = $data_getter->get($source->[1], $context); | |||||||||||||||||||||||||||||||||||||||||
| 716 | 2 | ▶ | if (defined $ctx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 717 | 1 | return Data::Org::Template::quote_substream (Data::Org::Template::_express_template ($source->[2]->{'.'}->[2], $data_getter, [$ctx, '*'], $indent, $transducer)); | |||||||||||||||||||||||||||||||||||||||||
| 718 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 719 | 1 | ▶ | if (exists $source->[2]->{'else'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | 1 | return Data::Org::Template::quote_substream (Data::Org::Template::_express_template ($source->[2]->{'else'}->[2], $data_getter, $context, $indent, $transducer)); | |||||||||||||||||||||||||||||||||||||||||
| 721 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | return Data::Org::Template::undef_stream(); | |||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | package Data::Org::Template::Transducer::list; | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 5 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | sub values { () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 732 | 5 | ▶ | sub tt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tt: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | 5 | my ($source, $data_getter, $context, $indent, $transducer) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 734 | 5 | my $iter = $data_getter->get_iterated ($source->[1], $context); | |||||||||||||||||||||||||||||||||||||||||
| 735 | 5 | my $alt = $source->[2]->{alt}; | |||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||
| 737 | 5 | ▶ | if (defined $iter) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | 4 | my $subctx; | |||||||||||||||||||||||||||||||||||||||||
| 739 | 4 | my $next_subctx = $iter->(); | |||||||||||||||||||||||||||||||||||||||||
| 740 | 4 | my $state = 0; # 0 = expressing row, 1 = expressing alt (if any) | |||||||||||||||||||||||||||||||||||||||||
| 741 | 4 | my $curstream; | |||||||||||||||||||||||||||||||||||||||||
| 742 | 4 | my $empty = 0; | |||||||||||||||||||||||||||||||||||||||||
| 743 | 33 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | 33 | ▶ | return undef if $empty; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 745 | DO_STREAM: | ||||||||||||||||||||||||||||||||||||||||||
| 746 | 42 | ▶ | if ($curstream) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 747 | 38 | my $tok = $curstream->(); | |||||||||||||||||||||||||||||||||||||||||
| 748 | 38 | ▶ | if (defined $tok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 749 | 29 | ▶ | return $tok if ref $tok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 750 | 29 | return ['"', $tok]; | |||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||
| 752 | 9 | $state = not $state; # We exhausted this stream, so go to the next - alt if we just did a row, row if we just did an alt. | |||||||||||||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||||||||||||
| 754 | # No stream active - let's start one. | ||||||||||||||||||||||||||||||||||||||||||
| 755 | NEXT_STATE: | ||||||||||||||||||||||||||||||||||||||||||
| 756 | 20 | ▶ | if ($state) { # We just did a row, so if there's an alt we should do it. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 757 | 8 | ▶ | if ($next_subctx and $alt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next_subctx and $alt
MC/DC100%2/2
$next_subctx and $alt
$next_subctx
$alt
Truth table100%3/3
A and B
A= $next_subctxB= $alt
| |||||||||||||||||||||||||||||||||||||||||||
| 758 | 1 | $curstream = Data::Org::Template::_express_template ($alt->[2], $data_getter, $subctx, $indent, $transducer); | |||||||||||||||||||||||||||||||||||||||||
| 759 | 1 | goto DO_STREAM; | |||||||||||||||||||||||||||||||||||||||||
| 760 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 761 | 7 | $state = 0; | |||||||||||||||||||||||||||||||||||||||||
| 762 | 7 | goto NEXT_STATE; | |||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||
| 764 | } else { # Start a new row. | ||||||||||||||||||||||||||||||||||||||||||
| 765 | 12 | $subctx = $next_subctx; | |||||||||||||||||||||||||||||||||||||||||
| 766 | 12 | $next_subctx = $iter->(); | |||||||||||||||||||||||||||||||||||||||||
| 767 | 12 | ▶ | if (defined $subctx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | 8 | $curstream = Data::Org::Template::_express_template ($source->[2]->{'.'}->[2], $data_getter, $subctx, $indent, $transducer); | |||||||||||||||||||||||||||||||||||||||||
| 769 | 8 | goto DO_STREAM; | |||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||
| 771 | 4 | $empty = 1; | |||||||||||||||||||||||||||||||||||||||||
| 772 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||||||||||
| 775 | 4 | } else { | |||||||||||||||||||||||||||||||||||||||||
| 776 | 1 | ▶ | if (exists $source->[2]->{'else'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 777 | 1 | return Data::Org::Template::quote_substream (Data::Org::Template::_express_template ($source->[2]->{'else'}->[2], $data_getter, $context, $indent, $transducer)); | |||||||||||||||||||||||||||||||||||||||||
| 778 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | return Data::Org::Template::undef_stream(); | |||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | Michael Roberts, C<< <michael at vivtek.com> >> | ||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | Please report any bugs or feature requests to C<bug-data-org at rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||||||||||||
| 793 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-Org-Template>. I will be notified, and then you'll | ||||||||||||||||||||||||||||||||||||||||||
| 794 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | perldoc Data::Org::Template | ||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||
| 812 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Org-Template> | ||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||
| 814 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||
| 816 | L<http://annocpan.org/dist/Data-Org-Template> | ||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||
| 820 | L<http://cpanratings.perl.org/d/Data-Org-Template> | ||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||
| 822 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||
| 824 | L<http://search.cpan.org/dist/Data-Org-Template/> | ||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||
| 832 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | Copyright 2020 Michael Roberts. | ||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||
| 836 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||
| 837 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||||||||||||||||||||||||
| 838 | copy of the full license at: | ||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||
| 840 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||||||||||||||||||||||||||||||||
| 843 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||||||||||||||||||||||||||||||||
| 844 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||||||||||||||||||||||||||||||||
| 845 | or distribute the Package, if you do not accept this license. | ||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||
| 847 | If your Modified Version has been derived from a Modified Version made | ||||||||||||||||||||||||||||||||||||||||||
| 848 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||||||||||||||||||||||||||||||||
| 849 | your Modified Version complies with the requirements of this license. | ||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||
| 851 | This license does not grant you the right to use any trademark, service | ||||||||||||||||||||||||||||||||||||||||||
| 852 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||
| 854 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||||||||||||||||||||||||||||||||
| 855 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||||||||||||||||||||||||||||||||
| 856 | otherwise transfer the Package with respect to any patent claims | ||||||||||||||||||||||||||||||||||||||||||
| 857 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||||||||||||||||||||||||||||||||
| 858 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||||||||||||||||||||||||||||||||
| 859 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||||||||||||||||||||||||||||||||
| 860 | direct or contributory patent infringement, then this Artistic License | ||||||||||||||||||||||||||||||||||||||||||
| 861 | to you shall terminate on the date that such litigation is filed. | ||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||
| 863 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||||||||||||||||||||||||||||||||
| 864 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||||||||||||||||||||||||||||||||
| 865 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||||||||||||||||||||||||||||||||
| 866 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||||||||||||||||||||||||||||||||
| 867 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||||||||||||||||||||||||||||||||
| 868 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||||||||||||||||||||||||||||||||
| 869 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||||||||||||||||||||||||||||||||
| 870 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||
| 873 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||
| 875 | 5 | 1; # End of Data::Org::Template | |||||||||||||||||||||||||||||||||||||||||