blib/lib/Astro/App/Satpass2/Format/Template.pm

filter: Statementstmt 85.6% 226 / 264 Branchbran 60.0% 66 / 110 Conditioncond 44.4% 12 / 27 MC/DCmcdc 12.5% 2 / 16 Subroutinesub 86.0% 43 / 50 Podpod 100% 11 / 11 totaltotal 75.3% 360 / 478 CC 70 SCAR 18.7
CC
70
Cov
76%
__default
25.7
config
20.0
format
14.0
CRAP 6.5
« blib/lib/Astro/App/Satpass2/Macro/Code.pm ↑ Summary blib/lib/Astro/App/Satpass2/Format/Dump.pm »
1 package Astro::App::Satpass2::Format::Template;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use parent qw{ Astro::App::Satpass2::Format };
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use Astro::App::Satpass2::Locale qw{ __localize };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 # use Astro::App::Satpass2::FormatValue;
10 8 ▶use Astro::App::Satpass2::FormatValue::Formatter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Astro::App::Satpass2::Utils qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
12 instance
13 load_package
14 ARRAY_REF
15 HASH_REF
16 SCALAR_REF
17 @CARP_NOT
18 8 };
19 8 ▶use Astro::App::Satpass2::Wrap::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use Astro::App::Satpass2::Format::Template::Provider;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶use Astro::Coord::ECI::TLE 0.059 qw{ :constants };
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 ▶use Astro::Coord::ECI::Utils 0.059 qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
23 deg2rad embodies julianday PI rad2deg TWOPI
24 8 };
25 8 ▶use Clone qw{ };
Subroutine BEGIN: called CC=1 SCAR=0.0
26 8 ▶use POSIX qw{ floor };
Subroutine BEGIN: called CC=1 SCAR=0.0
27 8 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 8 ▶use Text::Abbrev;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 8 ▶use Text::Wrap qw{ wrap };
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 8 our $VERSION = '0.059';
32  
33 8 ▶use constant FORMAT_VALUE => 'Astro::App::Satpass2::FormatValue';
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 9 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
36 9 my ($class, @args) = @_;
37 9 my $self = $class->SUPER::new( @args );
38  
39 # As of 0.020_002 the template definitions are in the
40 # locale system. The attribute simply holds modifications.
41 9 $self->{canned_template} = {};
42  
43 9 $self->_new_tt( $self->permissive() );
44  
45 9 $self->{default} = {};
46 9 $self->{formatter_method} = {};
47  
48 9 return $self;
49 }
50  
51 10 ▶sub _new_tt {
Subroutine _new_tt: called CC=2 SCAR=7.1
52 10 my ( $self, $permissive ) = @_;
53  
54 10 ▶ $self->{tt} = Template->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->{"tt"} = "Template"->new({"LOAD_TEMPLATES", ["Astro::App::Satpass2::Format::Template::Provider"->new("ABSOLUTE", $permissive, "RELATIVE", $permissive)]}) or $self->weep("Failed to instantate tt: $Template::ERROR") 10 0 10
55 {
56 LOAD_TEMPLATES => [
57 Astro::App::Satpass2::Format::Template::Provider->new(
58 ABSOLUTE => $permissive,
59 RELATIVE => $permissive,
60 ),
61 ],
62 }
63 ) or $self->weep(
64 "Failed to instantate tt: $Template::ERROR" );
65  
66 10 return;
67 }
68  
69 1 ▶sub add_formatter_method {
Subroutine add_formatter_method: called CC=6 SCAR=19.1
Pod documented
70 # TODO I want the arguments to be ( $self, $fmtr ), but for the
71 # moment I have to live with an unreleased version that passed the
72 # name as the first argument. I will go to the desired signature as
73 # soon as I get this version installed on my own machine.
74 1 my ( $self, @arg ) = @_;
75 1 ▶ my $fmtr = HASH_REF eq ref $arg[0] ? $arg[0] : $arg[1];
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq ref $arg[0] ? : 1 0 1
76 1 ▶ HASH_REF eq ref $fmtr
Branch: 1 branch
BranchTrueFalseTotal
"HASH" eq ref $fmtr or $self->wail("Formatter definition must be a HASH reference") 1 0 1
77 or $self->wail(
78 'Formatter definition must be a HASH reference' );
79 defined( my $fmtr_name = $fmtr->{name} )
80 1 ▶ or $self->wail(
Branch: 1 branch
BranchTrueFalseTotal
defined(my $fmtr_name = $fmtr->{"name"}) or $self->wail("Formatter definition must have {name} defined") 1 0 1
81 'Formatter definition must have {name} defined' );
82 $self->{formatter_method}{$fmtr_name}
83 and $self->{warner}->wail(
84 1 ▶ "Formatter method $fmtr_name already exists" );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"formatter_method"}{$fmtr_name} and $self->{"warner"}->wail("Formatter method $fmtr_name already exists") 0 1 1
85 FORMAT_VALUE->can( $fmtr_name )
86 and $self->{warner}->wail(
87 1 ▶ "Formatter $fmtr_name can not override built-in formatter" );
Branch: 1 branch
BranchTrueFalseTotal
"Astro::App::Satpass2::FormatValue"->can($fmtr_name) and $self->{"warner"}->wail("Formatter $fmtr_name can not override built-in formatter") 0 1 1
88 1 $self->{formatter_method}{$fmtr_name} =
89 Astro::App::Satpass2::FormatValue::Formatter->new( $fmtr );
90 1 return $self;
91 }
92  
93 17 ▶sub attribute_names {
Subroutine attribute_names: called CC=1 SCAR=0.0
Pod documented
94 17 my ( $self ) = @_;
95 17 return ( $self->SUPER::attribute_names(),
96 qw{ permissive },
97 );
98 }
99  
100 0 ▶sub config {
Subroutine config: not called CC=4 SCAR=30.0
Pod documented
101 0 my ( $self, %args ) = @_;
102 0 my @data = $self->SUPER::config( %args );
103  
104 # TODO support for the {default} key.
105  
106 0 ▶ foreach my $name (
Branch: 1 branch
BranchTrueFalseTotal
$args{'changes'} ? : 0 0 0
107 sort $args{changes} ?
108 0 keys %{ $self->{canned_template} } :
109 $self->__list_templates()
110 ) {
111 push @data, [ template => $name,
112 0 $self->{canned_template}{$name} ];
113 }
114  
115 0 ▶ return wantarray ? @data : \@data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
116 }
117  
118 # Return the names of all known templates, in no particular order. No
119 # arguments other than the invocant.
120 25 ▶sub __list_templates {
Subroutine __list_templates: called CC=1 SCAR=0.0
121 25 my ( $self ) = @_;
122 75 return ( _uniq( map { keys %{ $_ } } $self->{canned_template},
123 25 __localize(
124 text => '+template',
125 default => {},
126 ) ) );
127 }
128  
129 {
130 my %decoder = (
131 0 ▶ template => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
132 0 my ( $self, $method, @args ) = @_;
133  
134 =begin comment
135  
136 1 == @args
137 and return ( @args, $self->$method( @args ) );
138 $self->$method( @args );
139 return $self;
140  
141 =end comment
142  
143 =cut
144  
145 0 ▶ 1 == @args
Branch: 1 branch
BranchTrueFalseTotal
1 == @args or return $self->$method(@args) 0 0 0
146 or return $self->$method( @args );
147 0 return ( @args, $self->$method( @args ) );
148 },
149 8 );
150  
151 7 ▶ sub decode {
Subroutine decode: called CC=2 SCAR=8.1
Pod documented
152 7 my ( $self, $method, @args ) = @_;
153 7 ▶ my $dcdr = $decoder{$method}
Branch: 1 branch
BranchTrueFalseTotal
my $dcdr = $decoder{$method} or return $self->SUPER::decode($method, @args) 0 7 7
154 or return $self->SUPER::decode( $method, @args );
155 0 goto $dcdr;
156 }
157 }
158  
159 8 ▶sub __default {
Subroutine __default: called CC=6 SCAR=32.5
160 302 my ( $self, @arg ) = @_;
161 302 ▶ @arg or return $self->{default};
Branch: 1 branch
BranchTrueFalseTotal
@arg or return $self->{"default"} 0 302 302
162 0 my $action = shift @arg;
163 0 ▶ @arg or return $self->{default}{$action};
Branch: 1 branch
BranchTrueFalseTotal
@arg or return $self->{"default"}{$action} 0 0 0
164 0 my $attrib = shift @arg;
165 defined $attrib
166 0 ▶ or return delete $self->{default}{$action};
Branch: 1 branch
BranchTrueFalseTotal
defined $attrib or return delete $self->{"default"}{$action} 0 0 0
167 0 ▶ @arg or return $self->{default}{$action}{$attrib};
Branch: 1 branch
BranchTrueFalseTotal
@arg or return $self->{"default"}{$action}{$attrib} 0 0 0
168 0 my $value = shift @arg;
169 defined $value
170 0 ▶ or return delete $self->{default}{$action}{$attrib};
Branch: 1 branch
BranchTrueFalseTotal
defined $value or return delete $self->{"default"}{$action}{$attrib} 0 0 0
171 0 $self->{default}{$action}{$attrib} = $value;
172 0 return $value;
173 }
174  
175 62 ▶sub format : method { ## no critic (ProhibitBuiltInHomonyms)
Subroutine format: called CC=11 SCAR=26.4
Pod documented
176 62 my ( $self, %data ) = @_;
177  
178 exists $data{data}
179 and $data{data} = $self->_wrap(
180 data => $data{data},
181 report => $data{template},
182 62 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
exists $data{"data"} and $data{"data"} = $self->_wrap("data", $data{"data"}, "report", $data{"template"}) 59 3 62
183  
184 62 ▶ _is_format() and return $data{data};
Branch: 1 branch
BranchTrueFalseTotal
_is_format() and return $data{"data"} 1 61 62
185  
186 my $tplt = delete $data{template}
187 61 ▶ or $self->wail( 'template argument is required' );
Branch: 1 branch
BranchTrueFalseTotal
my $tplt = delete $data{"template"} or $self->wail("template argument is required") 61 0 61
188  
189 61 ▶ my $tplt_name = SCALAR_REF eq ref $tplt ? ${ $tplt } : $tplt;
Branch: 1 branch
BranchTrueFalseTotal
'SCALAR' eq ref $tplt ? : 1 60 61
190  
191 61 ▶ $data{default} ||= $self->__default();
Condition33%1/3
$data{"default"} ||= $self->__default
l!l&&r!l&&!r
0610
MC/DC0%0/2
$data{"default"} ||= $self->__default
$data{"default"} $self->__default
Truth table33%1/3
A ||= B
A= $data{"default"}B= $self->__default
ABresult
1X1
011
000
192  
193 0 ▶ $data{instantiate} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
194 0 my @args = @_;
195 0 my $class = Astro::App::Satpass2::Utils::load_package( @args );
196 0 return $class->new();
197 61 };
198  
199 61 ▶ $data{provider} ||= $self->provider();
Condition33%1/3
$data{"provider"} ||= $self->provider
l!l&&r!l&&!r
0610
MC/DC0%0/2
$data{"provider"} ||= $self->provider
$data{"provider"} $self->provider
Truth table33%1/3
A ||= B
A= $data{"provider"}B= $self->provider
ABresult
1X1
011
000
200  
201 61 ▶ if ( $data{time} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data{'time'}) { } 0 61 61
202 ref $data{time}
203 or $data{time} = $self->_wrap(
204 data => { time => $data{time} },
205 0 ▶ report => $tplt_name,
Branch: 1 branch
BranchTrueFalseTotal
ref $data{"time"} or $data{"time"} = $self->_wrap("data", {"time", $data{"time"}}, "report", $tplt_name) 0 0 0
206 );
207 } else {
208 61 $data{time} = $self->_wrap(
209 data => { time => time },
210 report => $tplt_name,
211 );
212 }
213  
214 61 my $value_formatter = $self->value_formatter();
215  
216 $data{title} = $self->_wrap(
217 default => $data{default},
218 61 report => $tplt_name,
219 );
220 $data{TITLE_GRAVITY_BOTTOM} =
221 61 $value_formatter->TITLE_GRAVITY_BOTTOM;
222 $data{TITLE_GRAVITY_TOP} =
223 61 $value_formatter->TITLE_GRAVITY_TOP;
224  
225 0 ▶ local $Template::Stash::LIST_OPS->{bodies} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
226 0 my ( $list ) = @_;
227 0 return [ map { $_->body() } @{ $list } ];
228 61 };
229  
230 3 ▶ local $Template::Stash::LIST_OPS->{events} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
231 3 my @args = @_;
232 3 return $self->_all_events( $args[0] );
233 61 };
234  
235 2 ▶ local $Template::Stash::LIST_OPS->{fixed_width} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
236 2 my ( $list, $value ) = @_;
237 2 foreach my $item ( @{ $list } ) {
238 10 ▶ my $code = $item->can( 'fixed_width' )
Branch: 1 branch
BranchTrueFalseTotal
my $code = $item->can("fixed_width") or next 10 0 10
239 or next;
240 10 $code->( $item, $value );
241 }
242 2 return;
243 61 };
244  
245 29 ▶ local $Template::Stash::LIST_OPS->{first_tle} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.7
246 29 my ( $list ) = @_;
247 29 foreach my $item ( @{ $list } ) {
248 29 ▶ embodies( $item->body(), 'Astro::Coord::ECI::TLE' )
Branch: 1 branch
BranchTrueFalseTotal
embodies($item->body, "Astro::Coord::ECI::TLE") and return $item 29 0 29
249 and return $item;
250 }
251 0 return;
252 61 };
253  
254 61 local $Template::Stash::LIST_OPS->{to_json} = do {
255 61 local $@ = undef;
256 eval {
257 61 load_package( 'JSON' );
258 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
259 0 my ( $list ) = @_;
260 0 my $json = JSON->new()->utf8()->allow_blessed()->convert_blessed();
261 0 $json->pretty()->canonical();
262 0 return $json->encode( $list );
263 }
264 61 ▶ } || sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
265 0 $self->wail( 'Module JSON could not be loaded' );
266 61 ▶ };
Condition33%1/3
eval { do { load_package('JSON'); sub { my($list) = @_; my $json = 'JSON'->new->utf8->allow_blessed->convert_blessed; $json->pretty->canonical; return $json->encode($list); } } } || sub { $self->wail('Module JSON could not be loaded'); }
l!l&&r!l&&!r
6100
MC/DC0%0/2
eval { do { load_package('JSON'); sub { my($list) = @_; my $json = 'JSON'->new->utf8->allow_blessed->convert_blessed; $json->pretty->canonical; return $json->encode($list); } } } || sub { $self->wail('Module JSON could not be loaded'); }
eval { do { load_package('JSON'); sub { my($list) = @_; my $json = 'JSON'->new->utf8->allow_blessed->convert_blessed; $json->pretty->canonical; return $json->encode($list); } } } sub { $self->wail('Module JSON could not be loaded'); }
Truth table33%1/3
A || B
A= eval { do { load_package('JSON'); sub { my($list) = @_; my $json = 'JSON'->new->utf8->allow_blessed->convert_blessed; $json->pretty->canonical; return $json->encode($list); } } }B= sub { $self->wail('Module JSON could not be loaded'); }
ABresult
1X1
011
000
267 };
268  
269 28 ▶ $data{localize} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
270 28 return _localize( $tplt_name, @_ );
271 61 };
272  
273 # NOTE - must come after $data{localize} because
274 # $data{format_detail} uses $data{localize}
275 173 ▶ $data{format_detail} = sub {
Subroutine __ANON__: called CC=5 SCAR=16.4
276 173 my ( $kind, $evt ) = @_;
277  
278 173 ▶ instance( $evt, FORMAT_VALUE )
Branch: 1 branch
BranchTrueFalseTotal
instance($evt, "Astro::App::Satpass2::FormatValue") or return 173 0 173
279 or return;
280 173 ▶ defined ( my $type = $evt->$kind( width => '' ) )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $type = $evt->$kind("width", "")) or return 173 0 173
281 or return;
282 173 $type =~ s/ \s+ \z //smx;
283  
284 173 foreach my $name ( "$kind:$type", $kind ) {
285 329 ▶ defined ( my $tplt = $self->template( "$tplt:$name" ) )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $tplt = $self->template("${tplt}:$name")) or next 173 156 329
286 or next;
287 my $output = $self->_process( \$tplt,
288 evt => $evt,
289 localize => $data{localize},
290 sp => $data{sp},
291 173 );
292  
293 173 chomp $output;
294 173 return $output;
295 }
296 0 return __localize(
297 text => [ '+template', "$tplt:$kind" ],
298 );
299 61 };
300  
301 61 my $output = $self->_process( $tplt, %data );
302  
303 # TODO would love to use \h here, but that needs 5.10.
304 60 $output =~ s/ [ \t]+ (?= \n ) //sxmg;
305 $data{title}->title_gravity() eq $data{TITLE_GRAVITY_BOTTOM}
306 60 ▶ and $output =~ s/ \A \n //smx;
Branch: 1 branch
BranchTrueFalseTotal
$data{"title"}->title_gravity eq $data{"TITLE_GRAVITY_BOTTOM"} and $output =~ s/ \A \n //msx 37 23 60
307  
308 60 return $output;
309 }
310  
311 57 ▶sub gmt {
Subroutine gmt: called CC=2 SCAR=6.9
Pod documented
312 57 my ( $self, @args ) = @_;
313 57 ▶ if ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 3 54 57
314 3 $self->time_formatter()->gmt( @args );
315 3 return $self->SUPER::gmt( @args );
316 } else {
317 54 return $self->SUPER::gmt();
318 }
319 }
320  
321 207 ▶sub local_coord {
Subroutine local_coord: called CC=4 SCAR=13.9
Pod documented
322 207 my ( $self, @args ) = @_;
323 207 ▶ if ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 12 195 207
324 12 my $val = $args[0];
325 12 ▶ defined $val
Branch: 1 branch
BranchTrueFalseTotal
defined $val or $val = $self->DEFAULT_LOCAL_COORD 10 2 12
326 or $val = $self->DEFAULT_LOCAL_COORD;
327  
328 12 ▶ defined $self->template( $val )
Branch: 1 branch
BranchTrueFalseTotal
defined $self->template($val) or $self->wail("Unknown local coordinate specification", $val) 12 0 12
329 or $self->wail(
330 'Unknown local coordinate specification', $val );
331  
332 12 return $self->SUPER::local_coord( @args );
333 } else {
334 195 return $self->SUPER::local_coord();
335 }
336 }
337  
338 10 ▶sub permissive {
Subroutine permissive: called CC=4 SCAR=14.6
Pod documented
339 10 my ( $self, @args ) = @_;
340 10 ▶ if ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 1 9 10
341 1 ▶ if ( $self->{permissive} xor $args[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"permissive"} xor $args[0]) 1 0 1
Condition25%1/4
$self->{"permissive"} xor $args[0]
l&&rl&&!r!l&&r!l&&!r
0010
MC/DC0%0/2
$self->{"permissive"} xor $args[0]
$self->{"permissive"} $args[0]
Truth table25%1/4
A xor B
A= $self->{"permissive"}B= $args[0]
ABresult
110
101
011
000
342 1 $self->_new_tt( $args[0] );
343 }
344 1 $self->{permissive} = $args[0];
345 1 return $self;
346 } else {
347 9 return $self->{permissive};
348 }
349 }
350  
351 620 ▶sub template {
Subroutine template: called CC=7 SCAR=21.1
Pod documented
352 620 my ( $self, $name, @value ) = @_;
353 620 ▶ defined $name
Branch: 1 branch
BranchTrueFalseTotal
defined $name or $self->wail("Template name not specified") 620 0 620
354 or $self->wail( 'Template name not specified' );
355  
356 620 ▶ if ( @value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@value) { } 3 617 620
357 3 my $tplt_text;
358 3 ▶ if ( ! defined $value[0]
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value[0] or defined($tplt_text = __localize('text', '+template', 'default', $value[0])) and $value[0] eq $tplt_text) { } 0 3 3
Condition33%2/6
not defined $value[0] or defined($tplt_text = __localize("text", "+template", "default", $value[0])) and $value[0] eq $tplt_text
l!l&&r!l&&!r
003
defined($tplt_text = __localize("text", "+template", "default", $value[0])) and $value[0] eq $tplt_text
!ll&&!rl&&r
030
MC/DC0%0/3
not defined $value[0] or defined($tplt_text = __localize("text", "+template", "default", $value[0])) and $value[0] eq $tplt_text
not defined $value[0] defined($tplt_text = __localize("text", "+template", "default", $value[0])) $value[0] eq $tplt_text
Truth table25%1/4
not(A) or B and C
A= not defined $value[0]B= defined($tplt_text = __localize("text", "+template", "default", $value[0]))C= $value[0] eq $tplt_text
ABCresult
1XX1
0111
00X0
0100
359 || defined( $tplt_text = __localize(
360 text => '+template',
361 default => $value[0] )
362 )
363 && $value[0] eq $tplt_text
364 ) {
365 0 delete $self->{canned_template}{$name};
366 } else {
367 3 $self->{canned_template}{$name} = $value[0];
368 }
369  
370 3 return $self;
371 } else {
372 defined $self->{canned_template}{$name}
373 617 ▶ and return $self->{canned_template}{$name};
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"canned_template"}{$name} and return $self->{"canned_template"}{$name} 4 613 617
374 613 return __localize(
375 text => [ '+template', $name ],
376 );
377 }
378 }
379  
380 16 ▶sub tz {
Subroutine tz: called CC=2 SCAR=7.2
Pod documented
381 16 my ( $self, @args ) = @_;
382 16 ▶ if ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 16 0 16
383 16 my $tf = $self->time_formatter();
384 # We go through the following because the time formatter may
385 # modify the zone (e.g. if it's using DateTime, zones are
386 # case-sensitive so we may have done case conversion before
387 # storing). We want this object to have the time formatter's
388 # version of the zone.
389 16 $tf->tz( @args );
390 16 return $self->SUPER::tz( $tf->tz() );
391 } else {
392 0 return $self->SUPER::tz();
393 }
394 }
395  
396 3 ▶sub _all_events {
Subroutine _all_events: called CC=4 SCAR=14.0
397 3 my ( $self, $data ) = @_;
398 3 ▶ ARRAY_REF eq ref $data or return;
Branch: 1 branch
BranchTrueFalseTotal
"ARRAY" eq ref $data or return 3 0 3
399  
400 3 my @events;
401 3 foreach my $pass ( @{ $data } ) {
402 3 push @events, $pass->__raw_events();
403 }
404 3 ▶ @events or return;
Branch: 1 branch
BranchTrueFalseTotal
@events or return 3 0 3
405 3 @events = sort { $a->{time} <=> $b->{time} } @events;
406  
407 3 return [ map { $self->_wrap( data => $_ ) } @events ];
408 }
409  
410 # _is_format()
411 #
412 # Returns true if the format() method is above us on the call
413 # stack, otherwise returns false.
414  
415 8 ▶use constant REPORT_CALLER => __PACKAGE__ . '::format';
Subroutine BEGIN: called CC=1 SCAR=0.0
416 62 ▶sub _is_format {
Subroutine _is_format: called CC=3 SCAR=11.0
417 62 my $level = 2; # Start with caller's caller.
418 62 ▶ while ( my @info = caller( $level ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@info) = caller $level) 343 61 404
419 343 ▶ REPORT_CALLER eq $info[3]
Branch: 1 branch
BranchTrueFalseTotal
"Astro::App::Satpass2::Format::Template::format" eq $info[3] and return $level 1 342 343
420 and return $level;
421 342 $level++;
422 }
423 61 return;
424 }
425  
426 28 ▶sub _localize {
Subroutine _localize: called CC=4 SCAR=16.1
427 28 my ( $report, $source, $default ) = @_;
428 28 ▶ defined $default
Branch: 1 branch
BranchTrueFalseTotal
defined $default or $default = $source 0 28 28
429 or $default = $source;
430 28 ▶ defined $report
Branch: 2 branches
BranchTrueFalseTotal
defined $report or return defined $source ? $source : $default 28 0 28
defined $source ? : 0 0 0
431 or return defined $source ? $source : $default;
432  
433 28 return scalar __localize(
434 text => [ "-$report", 'string', $source ],
435 default => $source,
436 );
437 }
438  
439 449 ▶sub _process {
Subroutine _process: called CC=6 SCAR=18.0
440 449 my ( $self, $tplt, %arg ) = @_;
441 ARRAY_REF eq ref $arg{arg}
442 and $arg{arg} = Astro::App::Satpass2::Wrap::Array->new(
443 449 ▶ $arg{arg} );
Branch: 1 branch
BranchTrueFalseTotal
"ARRAY" eq ref $arg{"arg"} and $arg{"arg"} = "Astro::App::Satpass2::Wrap::Array"->new($arg{"arg"}) 218 231 449
444 449 my $output;
445 449 my $tt = $self->{tt};
446  
447 # NOTE that what I really want is to be able to hook into the
448 # Template-Toolkit loading system. Because that is impossible (or at
449 # least I can't figure out how to do it) the following code
450 # special-cases template '%% INCLUDE ( \w+ )' (and reasonable
451 # equivalents) and loads the template directly. Note that this is
452 # what Template-Toolkit calls outline-tag syntax, but it works
453 # independentl;y of whether outline tags are enabled.
454 449 ▶ unless ( ref $tplt ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $tplt) 275 174 449
455 275 ▶ while ( defined( my $tplt_text = $self->template( $tplt ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $tplt_text = $self->template($tplt))) 272 3 275
456 272 ▶ if ( $tplt_text =~ m/\A %% \s* include \s+ ( \w+ ) \s* \z /smxi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tplt_text =~ /\A %% \s* include \s+ ( \w+ ) \s* \z /imsx) { } 0 272 272
457 0 $tplt = $1;
458 } else {
459 272 $tplt = \$tplt_text;
460 272 last;
461 }
462 }
463 }
464  
465 449 ▶ $tt->process( $tplt, \%arg, \$output )
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($tplt, \%arg, \$output) or $self->wail($tt->error) 448 1 449
466 or $self->wail( $tt->error() );
467 448 return $output;
468 }
469  
470 # Cribbed shamelessly from List::MoreUtils. The author reserves the
471 # right to relocate, rename or otherwise mung with this without notice
472 # to anyone. Caveat user.
473 26 ▶sub _uniq {
Subroutine _uniq: called CC=1 SCAR=0.0
474 26 my %found;
475 26 return ( grep { ! $found{$_}++ } @_ );
476 }
477  
478 517 ▶sub _wrap {
Subroutine _wrap: called CC=8 SCAR=20.9
479 517 my ( $self, %arg ) = @_;
480  
481 517 my $data = $arg{data};
482 517 my $default = $arg{default};
483 517 my $report = $arg{report};
484  
485 517 my $title = ! $data;
486 517 ▶ $data ||= {};
Condition100%2/2
$data ||= {}
l!l
241276
MC/DC100%1/1
$data ||= {}
$data
Truth table100%2/2
A
A= $data
Aresult
11
00
487 517 ▶ $default ||= $self->__default();
Condition66%2/3
$default ||= $self->__default
l!l&&r!l&&!r
2762410
MC/DC0%0/2
$default ||= $self->__default
$default $self->__default
Truth table66%2/3
A ||= B
A= $defaultB= $self->__default
ABresult
1X1
011
000
488  
489 517 ▶ if ( instance( $data, FORMAT_VALUE ) ) {
Branch: 4 branches
BranchTrueFalseTotal
if (instance($data, 'Astro::App::Satpass2::FormatValue')) { } 0 517 517
elsif (not defined $data or 'HASH' eq ref $data) { } 449 68 517
elsif ('ARRAY' eq ref $data) { } 45 23 68
elsif (embodies($data, 'Astro::Coord::ECI')) { } 23 0 23
490 # Do nothing
491 ▶ } elsif ( ! defined $data || HASH_REF eq ref $data ) {
Condition66%2/3
not defined $data or "HASH" eq ref $data
l!l&&r!l&&!r
044968
MC/DC50%1/2
not defined $data or "HASH" eq ref $data
not defined $data "HASH" eq ref $data
Truth table66%2/3
not(A) or B
A= not defined $dataB= "HASH" eq ref $data
ABresult
1X1
011
000
492 449 my $value_formatter = $self->value_formatter();
493 $data = $value_formatter->new(
494 data => $data,
495 default => $default,
496 date_format => $self->date_format(),
497 desired_equinox_dynamical =>
498 $self->desired_equinox_dynamical(),
499 provider => $self->provider(),
500 round_time => $self->round_time(),
501 time_format => $self->time_format(),
502 time_formatter => $self->time_formatter(),
503 195 ▶ local_coordinates => sub {
Subroutine __ANON__: called CC=1 SCAR=0.4
504 195 my ( $data, @arg ) = @_;
505 return $self->_process( $self->local_coord(),
506 data => $data,
507 arg => \@arg,
508 title => $self->_wrap(
509 default => $default,
510 report => $report,
511 ),
512 0 ▶ localize => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
513 0 return _localize( $report, @_ );
514 },
515 195 );
516 },
517 20 ▶ list_formatter => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
518 20 my ( $data, @arg ) = @_;
519 20 my $body = $data->body();
520 20 ▶ my $list_type = $body ? $body->__list_type() : 'inertial';
Branch: 1 branch
BranchTrueFalseTotal
$body ? : 8 12 20
521 20 return $self->_process( "list_$list_type",
522 data => $data,
523 arg => \@arg,
524 title => $self->_wrap(
525 default => $default,
526 report => $report,
527 ),
528 );
529 },
530 449 report => $report,
531 title => $title,
532 warner => $self->warner(),
533 );
534 449 $data->add_formatter_method( values %{ $self->{formatter_method} } );
535 } elsif ( ARRAY_REF eq ref $data ) {
536 45 $data = [ map { $self->_wrap( data => $_, report => $report ) } @{ $data } ];
537 } elsif ( embodies( $data, 'Astro::Coord::ECI' ) ) {
538 23 $data = $self->_wrap(
539 data => { body => $data },
540 report => $report,
541 );
542 }
543  
544 517 return $data;
545 }
546  
547 8 __PACKAGE__->create_attribute_methods();
548  
549 8 1;
550  
551 __END__
« blib/lib/Astro/App/Satpass2/Macro/Code.pm ↑ Summary blib/lib/Astro/App/Satpass2/Format/Dump.pm »