« blib/lib/Web/DataService/IRequest.pm
↑ Summary
blib/lib/Web/DataService/Plugin/TemplateToolkit.pm »
| 1 | # | ||||||||||||||||||||||||||||
| 2 | # Web::DataService::Render | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This module provides a role that is used by 'Web::DataService'. It | ||||||||||||||||||||||||||||
| 5 | # implements routines for generating documentation pages and output pages by | ||||||||||||||||||||||||||||
| 6 | # rendering templates. | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # Author: Michael McClennen | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Web::DataService::Render; | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # check_doc ( template ) | ||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||
| 21 | # Return the given template filename if the corresponding file path exists and | ||||||||||||||||||||||||||||
| 22 | # is readable under the documentation template directory. Throw an exception | ||||||||||||||||||||||||||||
| 23 | # if the file exists but is not readable. Return undefined (false) if the | ||||||||||||||||||||||||||||
| 24 | # file is not there. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub check_doc { | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my ($ds, $template_path) = @_; | ||||||||||||||||||||||||||
|
Subroutine
check_doc: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | return unless defined $template_path && $template_path ne ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $template_path and $template_path ne ""
MC/DC0%0/2
defined $template_path and $template_path ne ""
defined $template_path
$template_path ne ""
Truth table0%0/3
A and B
A= defined $template_pathB= $template_path ne ""
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $full_path = $Web::DataService::FOUNDATION->file_path($ds->{doc_template_dir}, $template_path); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ( -e $full_path ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return $template_path if -r $full_path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | croak "template $template_path: $!"; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | return; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # read_doc_partial ( path ) | ||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||
| 46 | # Read the first 2048 characters of the specified template file and return | ||||||||||||||||||||||||||||
| 47 | # them. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub read_doc_partial { | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my ($ds, $template_path) = @_; | ||||||||||||||||||||||||||
|
Subroutine
read_doc_partial: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my $full_path = $Web::DataService::FOUNDATION->file_path($ds->{doc_template_dir}, $template_path); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | open(my $fh, "<", $full_path) || die "cannot read documentation template '$full_path': $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | sysread($fh, my $contents, 2048); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | return $contents; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # render_doc ( template, definitions, header, footer, vars ) | ||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||
| 64 | # Render the specified template, with the specified parameters. If | ||||||||||||||||||||||||||||
| 65 | # $definitions and/or $header are defined, process them before the main | ||||||||||||||||||||||||||||
| 66 | # template. If $footer is defined, process it after the main template. If | ||||||||||||||||||||||||||||
| 67 | # $vars is defined, it must be a hashref of variable definitions that will be | ||||||||||||||||||||||||||||
| 68 | # passed to the template rendering engine. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub render_doc { | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my ($ds, $main, $defs, $header, $footer, $vars) = @_; | ||||||||||||||||||||||||||
|
Subroutine
render_doc: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # Throw an exception if no templating module was selected. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | croak "you must select a templating module" | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | unless defined $ds->{templating_plugin}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | my $templates = { defs => $defs, header => $header, | |||||||||||||||||||||||||||
| 80 | main => $main, footer => $footer }; | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | $ds->{templating_plugin}->render_template($ds, $ds->{doc_engine}, $vars, $templates); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # check_output ( template ) | ||||||||||||||||||||||||||||
| 87 | # | ||||||||||||||||||||||||||||
| 88 | # Return the given template filename if the corresponding file path exists and | ||||||||||||||||||||||||||||
| 89 | # is readable under the output template directory. Throw an exception if the | ||||||||||||||||||||||||||||
| 90 | # file exists but is not readable. Return undefined (false) if the file is | ||||||||||||||||||||||||||||
| 91 | # not there. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub check_output { | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my ($ds, $template) = @_; | ||||||||||||||||||||||||||
|
Subroutine
check_output: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | return unless defined $template && $template ne ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $template and $template ne ""
MC/DC0%0/2
defined $template and $template ne ""
defined $template
$template ne ""
Truth table0%0/3
A and B
A= defined $templateB= $template ne ""
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | my $template_file = $Web::DataService::FOUNDATION->file_path($ds->{output_templates}, $template); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ( -e $template_file ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return $template if -r $template_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | croak "template $template_file: $!"; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | return; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # render_output ( template, definitions, header, footer, vars ) | ||||||||||||||||||||||||||||
| 112 | # | ||||||||||||||||||||||||||||
| 113 | # Render the specified template, with the specified parameters. If | ||||||||||||||||||||||||||||
| 114 | # $definitions and/or $header are defined, process them before the main | ||||||||||||||||||||||||||||
| 115 | # template. If $footer is defined, process it after the main template. If | ||||||||||||||||||||||||||||
| 116 | # $vars is defined, it must be a hashref of variable definitions that will be | ||||||||||||||||||||||||||||
| 117 | # passed to the template rendering engine. | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | sub render_output { | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | my $ds = shift; | ||||||||||||||||||||||||||
|
Subroutine
render_output: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # Throw an exception if no templating module was selected. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | croak "you must select a templating module" | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | unless defined $ds->{templating_plugin}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | $ds->{templating_plugin}->render_template($ds->{doc_templates}, @_); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 2 | 1; | |||||||||||||||||||||||||||