« blib/lib/auto/share/dist/Amon2/flavor/Basic/lib/__PATH__.pm
↑ Summary
blib/lib/auto/share/dist/Amon2/flavor/Minimum/lib/__PATH__/Web/ViewFunctions.pm »
| 1 | package <% $module %>::<% $moniker %>::ViewFunctions; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use utf8; | ||
| 5 | use parent qw(Exporter); | ||
| 6 | use Module::Functions; | ||
| 7 | use File::Spec; | ||
| 8 | |||
| 9 | our @EXPORT = get_public_functions(); | ||
| 10 | |||
| 11 | sub commify { | ||
| 12 | local $_ = shift; | ||
| 13 | 1 while s/((?:\A|[^.0-9])[-+]?\d+)(\d{3})/$1,$2/s; | ||
| 14 | return $_; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub c { <% $module %>->context() } | ||
| 18 | sub uri_with { <% $module %>->context()->req->uri_with(@_) } | ||
| 19 | sub uri_for { <% $module %>->context()->uri_for(@_) } | ||
| 20 | |||
| 21 | { | ||
| 22 | my %static_file_cache; | ||
| 23 | sub static_file { | ||
| 24 | my $fname = shift; | ||
| 25 | (my $relpath = $fname) =~ s!static!static/<% $lc_moniker %>!; | ||
| 26 | my $c = <% $module %>->context; | ||
| 27 | if (not exists $static_file_cache{$relpath}) { | ||
| 28 | my $fullpath = File::Spec->catfile($c->base_dir(), $relpath); | ||
| 29 | $static_file_cache{$relpath} = (stat $fullpath)[9]; | ||
| 30 | } | ||
| 31 | return $c->uri_for( | ||
| 32 | $fname, { | ||
| 33 | 't' => $static_file_cache{$relpath} || 0 | ||
| 34 | } | ||
| 35 | ); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; |