| 1 | 441 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Role::Render; | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Render role | ||||||||||||||||||||||||||||
| 5 | 441 | $HTML::FormFu::Role::Render::VERSION = '2.09'; | |||||||||||||||||||||||||||
| 6 | 441 | ▶ | use HTML::FormFu::Util qw( process_attrs ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 441 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 441 | ▶ | use Scalar::Util qw( reftype ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 441 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 441 | our $SHARE_DIR; | |||||||||||||||||||||||||||
| 13 | 441 | our $SHARE_ERROR; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1139 | ▶ | sub render { | ||||||||||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 1139 | my $self = shift; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1139 | ▶ | my $render_method = $ENV{HTML_FORMFU_RENDER_METHOD} || $self->render_method; | ||||||||||||||||||||||||||
|
Condition33%1/3
$ENV{'HTML_FORMFU_RENDER_METHOD'} || $self->render_method
MC/DC0%0/2
$ENV{'HTML_FORMFU_RENDER_METHOD'} || $self->render_method
$ENV{'HTML_FORMFU_RENDER_METHOD'}
$self->render_method
Truth table33%1/3
A || B
A= $ENV{'HTML_FORMFU_RENDER_METHOD'}B= $self->render_method
| |||||||||||||||||||||||||||||
| 19 | 1139 | my $output = $self->$render_method(@_); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1139 | for my $proc ( @{ $self->form->get_output_processors } ) { | |||||||||||||||||||||||||||
| 22 | 31 | $output = $proc->process($output); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1139 | return $output; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 8 | ▶ | sub tt { | ||||||||||||||||||||||||||
|
Subroutine
tt: called CC=15 SCAR=29.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 8 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 8 | ▶ | $args ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args ||= {}
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 8 | ▶ | $args->{filename} = $self->filename if !exists $args->{filename}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 8 | ▶ | $args->{render_data} = $self->render_data if !exists $args->{render_data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 8 | my $form = $self->form; | |||||||||||||||||||||||||||
| 37 | 8 | my $share_dir = _share_dir(); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 8 | my %args = %{ $self->tt_args }; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 8 | ▶ | if ( defined $share_dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # add $share_dir to the end of INCLUDE_PATH | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | $args{INCLUDE_PATH} | ||||||||||||||||||||||||||||
| 46 | = exists $args{INCLUDE_PATH} | ||||||||||||||||||||||||||||
| 47 | ? ref $args{INCLUDE_PATH} eq 'ARRAY' | ||||||||||||||||||||||||||||
| 48 | 2 | ? [ @{ $args{INCLUDE_PATH} }, $share_dir ] | |||||||||||||||||||||||||||
| 49 | 8 | ▶ | : [ $args{INCLUDE_PATH}, $share_dir ] | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 50 | : [$share_dir]; | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 8 | ▶ | $args{ENCODING} = 'UTF-8' if !exists $args{ENCODING}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 8 | $args{RELATIVE} = 1; | |||||||||||||||||||||||||||
| 55 | 8 | $args{RECURSION} = 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 8 | my $tt_module = $form->tt_module; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | $tt_module = $ENV{HTML_FORMFU_TT_MODULE} | ||||||||||||||||||||||||||||
| 60 | if defined $ENV{HTML_FORMFU_TT_MODULE} | ||||||||||||||||||||||||||||
| 61 | 8 | ▶ | && length $ENV{HTML_FORMFU_TT_MODULE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ENV{"HTML_FORMFU_TT_MODULE"} and length $ENV{"HTML_FORMFU_TT_MODULE"}
MC/DC0%0/2
defined $ENV{"HTML_FORMFU_TT_MODULE"} and length $ENV{"HTML_FORMFU_TT_MODULE"}
defined $ENV{"HTML_FORMFU_TT_MODULE"}
length $ENV{"HTML_FORMFU_TT_MODULE"}
Truth table33%1/3
A and B
A= defined $ENV{"HTML_FORMFU_TT_MODULE"}B= length $ENV{"HTML_FORMFU_TT_MODULE"}
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 8 | my $class = $tt_module; | |||||||||||||||||||||||||||
| 64 | 8 | $class =~ s|::|/|g; | |||||||||||||||||||||||||||
| 65 | 8 | $class .= ".pm"; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 8 | ▶ | if ( !exists $::INC{$class} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 1 | eval { require $class }; | |||||||||||||||||||||||||||
| 69 | 1 | ▶ | croak $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 8 | my $template = $tt_module->new( \%args ); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 8 | my $output; | |||||||||||||||||||||||||||
| 75 | my %vars = ( | ||||||||||||||||||||||||||||
| 76 | self => $args->{render_data}, | ||||||||||||||||||||||||||||
| 77 | 8 | process_attrs => \&process_attrs, | |||||||||||||||||||||||||||
| 78 | reftype => \&reftype, | ||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 8 | ▶ | if ( !$template->process( $args->{filename}, \%vars, \$output ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | my $error = $template->error; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( $error->type() eq 'file' && $error =~ /not found/i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$error->type eq "file" and $error =~ /not found/i
MC/DC0%0/2
$error->type eq "file" and $error =~ /not found/i
$error->type eq "file"
$error =~ /not found/i
Truth table0%0/3
A and B
A= $error->type eq "file"B= $error =~ /not found/i
| |||||||||||||||||||||||||||||
| 86 | 0 | croak <<ERROR_MESSAGE; | |||||||||||||||||||||||||||
| 87 | $error | ||||||||||||||||||||||||||||
| 88 | The template files should have been installed somewhere in \@INC as part of | ||||||||||||||||||||||||||||
| 89 | the installation process. | ||||||||||||||||||||||||||||
| 90 | If you're using Catalyst, see Catalyst::Helper::HTML::FormFu. | ||||||||||||||||||||||||||||
| 91 | Alternatively, you can create a local copy of the files by running | ||||||||||||||||||||||||||||
| 92 | `html_formfu_deploy.pl`. | ||||||||||||||||||||||||||||
| 93 | Then set \$form->tt_args->{INCLUDE_PATH} to point to the template directory. | ||||||||||||||||||||||||||||
| 94 | ERROR_MESSAGE | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||
| 98 | 0 | croak $error; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 8 | return $output; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 8 | ▶ | sub _share_dir { | ||||||||||||||||||||||||||
|
Subroutine
_share_dir: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 8 | ▶ | return $SHARE_DIR if defined $SHARE_DIR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 6 | ▶ | return if $SHARE_ERROR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 6 | eval { | |||||||||||||||||||||||||||
| 112 | 6 | require File::ShareDir; | |||||||||||||||||||||||||||
| 113 | 6 | require File::Spec; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # dist_dir() doesn't reliably return the directory our files are in. | ||||||||||||||||||||||||||||
| 116 | # find the path of one of our files, then get the directory from that | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 6 | my $path = File::ShareDir::dist_file( 'HTML-FormFu', | |||||||||||||||||||||||||||
| 119 | 'templates/tt/xhtml/form' ); | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 6 | my ( $volume, $dirs ) = File::Spec->splitpath($path); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 6 | $SHARE_DIR = File::Spec->catpath( $volume, $dirs, '' ); | |||||||||||||||||||||||||||
| 124 | }; | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 6 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | $SHARE_DIR = undef; | |||||||||||||||||||||||||||
| 128 | 0 | $SHARE_ERROR = 1; | |||||||||||||||||||||||||||
| 129 | 0 | return; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 6 | return $SHARE_DIR; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 441 | 1; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | __END__ | ||||||||||||||||||||||||||||