« blib/lib/auto/share/dist/Amon2/flavor/Large/lib/__PATH__/__MONIKER__/ViewFunctions.pm
↑ Summary
blib/lib/Amon2/Plugin/Web/WebSocket.pm »
| 1 | package <% $package // $module ~ "::Web::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 $c = <% $module %>->context; | ||
| 26 | if (not exists $static_file_cache{$fname}) { | ||
| 27 | my $fullpath = File::Spec->catfile($c->base_dir(), $fname); | ||
| 28 | $static_file_cache{$fname} = (stat $fullpath)[9]; | ||
| 29 | } | ||
| 30 | return $c->uri_for( | ||
| 31 | $fname, { | ||
| 32 | 't' => $static_file_cache{$fname} || 0 | ||
| 33 | } | ||
| 34 | ); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; |