| 1 | |||||||||||||||||||
| 2 | package Mojolicious::Plugin::AlloyRenderer; | ||||||||||||||||||
| 3 | 6 | ▶ | BEGIN { | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 6 | $Mojolicious::Plugin::AlloyRenderer::AUTHORITY = 'cpan:AJGB'; | |||||||||||||||||
| 5 | } | ||||||||||||||||||
| 6 | { | ||||||||||||||||||
| 7 | 6 | $Mojolicious::Plugin::AlloyRenderer::VERSION = '1.121150'; | |||||||||||||||||
| 8 | } | ||||||||||||||||||
| 9 | #ABSTRACT: Template::Alloy renderer plugin | ||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 6 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | 6 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | 6 | ▶ | use base 'Mojolicious::Plugin'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | 6 | ▶ | use Mojo::Loader; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 6 | my %syn2ext = ( | |||||||||||||||||
| 21 | 'TT' => 'tt', | ||||||||||||||||||
| 22 | 'Velocity' => 'vtl', | ||||||||||||||||||
| 23 | 'Tmpl' => 'tmpl', | ||||||||||||||||||
| 24 | 'HTE' => 'hte', | ||||||||||||||||||
| 25 | ); | ||||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | 5 | ▶ | sub register { | ||||||||||||||||
|
Subroutine
register: called CC=11 SCAR=34.1
Pod
documented
| |||||||||||||||||||
| 28 | 5 | my ($self, $app, $args) = @_; | |||||||||||||||||
| 29 | 5 | ▶ | $args ||= {}; | ||||||||||||||||
|
Condition50%1/2
$args ||= {}
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | 5 | my @setup; | |||||||||||||||||
| 32 | 5 | ▶ | if ( my $s = delete $args->{syntax} ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 33 | # default extensions | ||||||||||||||||||
| 34 | # syntax => [qw( TT HTE )] | ||||||||||||||||||
| 35 | 5 | ▶ | if ( ref $s eq 'ARRAY' ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 36 | push @setup, [ $_ => $syn2ext{$_} ] | ||||||||||||||||||
| 37 | 0 | for @$s; | |||||||||||||||||
| 38 | } | ||||||||||||||||||
| 39 | # custom extensions | ||||||||||||||||||
| 40 | # syntax => {(TT => 'tt3', HTE => 'ht' )} | ||||||||||||||||||
| 41 | elsif ( ref $s eq 'HASH' ) { | ||||||||||||||||||
| 42 | 0 | ▶ | while (my($k,$v) = each %$s) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 43 | 0 | push @setup, [ $k => $v ]; | |||||||||||||||||
| 44 | } | ||||||||||||||||||
| 45 | } | ||||||||||||||||||
| 46 | # single syntax with default extension | ||||||||||||||||||
| 47 | # syntax => 'HTE' | ||||||||||||||||||
| 48 | elsif ( ! ref $s ) { | ||||||||||||||||||
| 49 | 5 | ▶ | if ( $s eq ':all' ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 50 | push @setup, [ $_ => $syn2ext{$_} ] | ||||||||||||||||||
| 51 | 1 | for sort keys %syn2ext; | |||||||||||||||||
| 52 | } else { | ||||||||||||||||||
| 53 | 4 | push @setup, [ $s => $syn2ext{$s} ]; | |||||||||||||||||
| 54 | } | ||||||||||||||||||
| 55 | } | ||||||||||||||||||
| 56 | else { | ||||||||||||||||||
| 57 | 0 | die "Unrecognised configuration for 'alloy_renderer' plugin: $s\n"; | |||||||||||||||||
| 58 | } | ||||||||||||||||||
| 59 | # defaults to TT | ||||||||||||||||||
| 60 | } else { | ||||||||||||||||||
| 61 | 0 | push @setup, [ TT => $syn2ext{TT} ]; | |||||||||||||||||
| 62 | } | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | 5 | my $loader = Mojo::Loader->new; | |||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | 0 | for my $syn ( @setup ) { | |||||||||||||||||
| 67 | 0 | my ($module, $extension) = @$syn; | |||||||||||||||||
| 68 | 0 | my $class = "MojoX::Renderer::Alloy::$module"; | |||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | 0 | $loader->load( $class ); | |||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | 0 | my $alloy = $class->build(%$args, app => $app); | |||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | 0 | $app->renderer->add_handler($extension => $alloy); | |||||||||||||||||
| 75 | 0 | $app->renderer->default_handler($extension); | |||||||||||||||||
| 76 | } | ||||||||||||||||||
| 77 | } | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | |||||||||||||||||||
| 80 | 6 | 1; | |||||||||||||||||
| 81 | |||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||