| 1 | package CGI::Application::Magic ; | ||
| 2 | $VERSION = 1.21 ; | ||
| 3 | 1 | ▶ | use strict ; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | # This file uses the "Perlish" coding style | ||
| 6 | # please read http://perl.4pro.net/perlish_coding_style.html | ||
| 7 | |||
| 8 | 1 | ▶ | ; use base 'CGI::Application::Plus' |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ; use Carp | |
| 11 | ; use File::Spec | ||
| 12 | ; use Template::Magic qw| -compile | ||
| 13 | TableTiler | ||
| 14 | FillInForm | ||
| 15 | | | ||
| 16 | |||
| 17 | ; use Object::groups | ||
| 18 | ( { name => 'tm_defaults' | ||
| 19 | , no_strict => 1 | ||
| 20 | } | ||
| 21 | ) | ||
| 22 | |||
| 23 | ; *tm_path = sub : lvalue { shift()->tmpl_path(@_) } | ||
| 24 | |||
| 25 | ; use Object::props | ||
| 26 | ( { name => 'tm_lookups' | ||
| 27 | } | ||
| 28 | , { name => 'tm_template' | ||
| 29 | , default => sub | ||
| 30 | { $_[0]->runmode | ||
| 31 | . $_[0]->tm_suffix | ||
| 32 | } | ||
| 33 | } | ||
| 34 | , { name => 'tm_lookups_package' | ||
| 35 | , default => sub{ ref($_[0]) . '::Lookups' } | ||
| 36 | } | ||
| 37 | , { name => 'tm_suffix' | ||
| 38 | , default => '.html' | ||
| 39 | } | ||
| 40 | , { name => 'page' | ||
| 41 | , default => sub | ||
| 42 | { sub # _tm_print is overridable | ||
| 43 | { shift()->_tm_print(@_) | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
| 47 | , { name => 'tm_object' | ||
| 48 | , default => sub{ shift()->tm_new_object(@_) } | ||
| 49 | } | ||
| 50 | ) | ||
| 51 | |||
| 52 | ; sub tm_new_object | ||
| 53 | { my ($s) = @_ | ||
| 54 | ; Template::Magic | ||
| 55 | ->new( lookups => [ $s->tm_lookups_package ] | ||
| 56 | , value_handlers => [ $s->lookup_CODE() | ||
| 57 | , 'HTML' | ||
| 58 | ] | ||
| 59 | , markers => 'HTML' | ||
| 60 | , defined $s->tm_defaults ? %{$s->tm_defaults} : () | ||
| 61 | ) | ||
| 62 | } | ||
| 63 | |||
| 64 | ; sub _tm_print | ||
| 65 | { my ($s) = @_ | ||
| 66 | ; my $t = $s->tm_template | ||
| 67 | ; my $lkps = $s->tm_lookups | ||
| 68 | ; $lkps &&= [ $lkps ] unless ref $lkps eq 'ARRAY' | ||
| 69 | ; my $err = eval{$s->dfv_results->msgs} | ||
| 70 | ; $s->tm_object | ||
| 71 | ->nprint( template => File::Spec | ||
| 72 | ->file_name_is_absolute( $t ) | ||
| 73 | ? $t | ||
| 74 | : File::Spec->catfile( $s->tm_path | ||
| 75 | , $t | ||
| 76 | ) | ||
| 77 | , lookups => [ defined $lkps ? @$lkps : () | ||
| 78 | , defined $err ? $err : () | ||
| 79 | ] | ||
| 80 | ) | ||
| 81 | |||
| 82 | } | ||
| 83 | |||
| 84 | ; sub lookup_CODE # value handler | ||
| 85 | { my ($s) = @_ | ||
| 86 | ; sub | ||
| 87 | { my ($z) = @_ | ||
| 88 | ; if ( ref $z->value eq 'CODE' | ||
| 89 | && $z->location eq $s->tm_lookups_package | ||
| 90 | ) | ||
| 91 | { $z->value = $z->value->($s, @_) | ||
| 92 | ; $z->value_process | ||
| 93 | ; 1 | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | ; sub setup {} | ||
| 99 | |||
| 100 | ; 1 | ||
| 101 | |||
| 102 | __END__ | ||