Astro-App-Satpass2
view release on metacpan or search on metacpan
lib/Astro/App/Satpass2/Format/Template.pm view on Meta::CPAN
if ( ! defined $value[0]
|| defined( $tplt_text = __localize(
text => '+template',
default => $value[0] )
)
&& $value[0] eq $tplt_text
) {
delete $self->{canned_template}{$name};
} else {
$self->{canned_template}{$name} = $value[0];
}
return $self;
} else {
defined $self->{canned_template}{$name}
and return $self->{canned_template}{$name};
return __localize(
text => [ '+template', $name ],
);
}
}
sub tz {
my ( $self, @args ) = @_;
if ( @args ) {
my $tf = $self->time_formatter();
# We go through the following because the time formatter may
# modify the zone (e.g. if it's using DateTime, zones are
# case-sensitive so we may have done case conversion before
# storing). We want this object to have the time formatter's
# version of the zone.
$tf->tz( @args );
return $self->SUPER::tz( $tf->tz() );
} else {
return $self->SUPER::tz();
}
}
sub _all_events {
my ( $self, $data ) = @_;
ARRAY_REF eq ref $data or return;
my @events;
foreach my $pass ( @{ $data } ) {
push @events, $pass->__raw_events();
}
@events or return;
@events = sort { $a->{time} <=> $b->{time} } @events;
return [ map { $self->_wrap( data => $_ ) } @events ];
}
# _is_format()
#
# Returns true if the format() method is above us on the call
# stack, otherwise returns false.
use constant REPORT_CALLER => __PACKAGE__ . '::format';
sub _is_format {
my $level = 2; # Start with caller's caller.
while ( my @info = caller( $level ) ) {
REPORT_CALLER eq $info[3]
and return $level;
$level++;
}
return;
}
sub _localize {
my ( $report, $source, $default ) = @_;
defined $default
or $default = $source;
defined $report
or return defined $source ? $source : $default;
return scalar __localize(
text => [ "-$report", 'string', $source ],
default => $source,
);
}
sub _process {
my ( $self, $tplt, %arg ) = @_;
ARRAY_REF eq ref $arg{arg}
and $arg{arg} = Astro::App::Satpass2::Wrap::Array->new(
$arg{arg} );
my $output;
my $tt = $self->{tt};
# NOTE that what I really want is to be able to hook into the
# Template-Toolkit loading system. Because that is impossible (or at
# least I can't figure out how to do it) the following code
# special-cases template '%% INCLUDE ( \w+ )' (and reasonable
# equivalents) and loads the template directly. Note that this is
# what Template-Toolkit calls outline-tag syntax, but it works
# independentl;y of whether outline tags are enabled.
unless ( ref $tplt ) {
while ( defined( my $tplt_text = $self->template( $tplt ) ) ) {
if ( $tplt_text =~ m/\A %% \s* include \s+ ( \w+ ) \s* \z /smxi ) {
$tplt = $1;
} else {
$tplt = \$tplt_text;
last;
}
}
}
$tt->process( $tplt, \%arg, \$output )
or $self->wail( $tt->error() );
return $output;
}
# Cribbed shamelessly from List::MoreUtils. The author reserves the
# right to relocate, rename or otherwise mung with this without notice
# to anyone. Caveat user.
sub _uniq {
my %found;
return ( grep { ! $found{$_}++ } @_ );
}
sub _wrap {
( run in 0.708 second using v1.01-cache-2.11-cpan-5fbc6bb55f2 )