| 1 | #============================================================= -*-Perl-*- | ||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||
| 3 | # Template::Plugin::HTML | ||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 6 | # Template Toolkit plugin providing useful functionality for generating | ||||||||||||||||||||||||||||||||||
| 7 | # HTML. | ||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||
| 9 | # AUTHOR | ||||||||||||||||||||||||||||||||||
| 10 | # Andy Wardley <abw@wardley.org> | ||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||
| 12 | # COPYRIGHT | ||||||||||||||||||||||||||||||||||
| 13 | # Copyright (C) 1996-2022 Andy Wardley. All Rights Reserved. | ||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||
| 15 | # This module is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||
| 16 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||
| 18 | #============================================================================ | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | package Template::Plugin::HTML; | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use base 'Template::Plugin'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | 1 | our $VERSION = '3.106'; | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 29 | 7 | my ($class, $context, @args) = @_; | |||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | my $hash = ref $args[-1] eq 'HASH' ? pop @args : { }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 31 | bless { | ||||||||||||||||||||||||||||||||||
| 32 | _SORTED => $hash->{ sorted } || 0, | ||||||||||||||||||||||||||||||||||
| 33 | attributes => $hash->{ attributes } || $hash->{ attrs } || { }, | ||||||||||||||||||||||||||||||||||
| 34 | 7 | ▶ | }, $class; | ||||||||||||||||||||||||||||||||
|
Condition57%4/7
$hash->{'sorted'} || 0
$hash->{'attributes'} || $hash->{'attrs'} || {}
$hash->{"attributes"} or $hash->{"attrs"}
MC/DC100%1/1
$hash->{'sorted'} || 0
$hash->{'sorted'}
MC/DC0%0/2
$hash->{'attributes'} || $hash->{'attrs'} || {}
$hash->{"attributes"}
$hash->{"attrs"}
Truth table100%2/2
A
A= $hash->{'sorted'}
Truth table33%1/3
A or B
A= $hash->{"attributes"}B= $hash->{"attrs"}
| |||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | sub element { | ||||||||||||||||||||||||||||||||
|
Subroutine
element: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 38 | 1 | my ($self, $name, $attr) = @_; | |||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | ($name, $attr) = %$name if ref $name eq 'HASH'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | return '' unless defined $name and length $name; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $name and length $name
MC/DC0%0/2
defined $name and length $name
defined $name
length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||||||||
| 41 | 1 | $attr = $self->attributes($attr); | |||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | $attr = " $attr" if $attr; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 43 | 1 | return "<$name$attr>"; | |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub closed_element { | ||||||||||||||||||||||||||||||||
|
Subroutine
closed_element: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 47 | 0 | my ($self, $name, $attr) = @_; | |||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | ($name, $attr) = %$name if ref $name eq 'HASH'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return '' unless defined $name and length $name; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and length $name
MC/DC0%0/2
defined $name and length $name
defined $name
length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||||||||
| 50 | 0 | $attr = $self->attributes( $attr ); | |||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $attr = " $attr" if $attr; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 52 | 0 | return "<$name$attr />"; | |||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | sub attributes { | ||||||||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 56 | 2 | my ($self, $hash) = @_; | |||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | $hash ||= $self->{ attributes }; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$hash ||= $self->{"attributes"}
MC/DC0%0/2
$hash ||= $self->{"attributes"}
$hash
$self->{"attributes"}
Truth table33%1/3
A ||= B
A= $hashB= $self->{"attributes"}
| |||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | return '' unless ref $hash eq 'HASH'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 2 | my @keys = keys %$hash; | |||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | @keys = sort @keys if $self->{ _SORTED }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | join(' ', map { | ||||||||||||||||||||||||||||||||||
| 64 | 2 | "$_=\"" . $self->escape( $hash->{ $_ } ) . '"'; | |||||||||||||||||||||||||||||||||
| 65 | } @keys); | ||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub add_attributes { | ||||||||||||||||||||||||||||||||
|
Subroutine
add_attributes: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 69 | 0 | my ($self, $attr) = @_; | |||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | return unless ref $attr eq 'HASH'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 0 | my $cur = $self->{ attributes }; | |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | 0 | for (keys %{$attr}) { | |||||||||||||||||||||||||||||||||
| 75 | $cur->{$_} = exists $cur->{$_} | ||||||||||||||||||||||||||||||||||
| 76 | ? $cur->{$_} . " $attr->{$_}" | ||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | : $attr->{$_}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 0 | return; | |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 1 | *add_attribute = \&add_attributes; | |||||||||||||||||||||||||||||||||
| 85 | 1 | *add = \&add_attributes; | |||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub replace_attributes { | ||||||||||||||||||||||||||||||||
|
Subroutine
replace_attributes: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 89 | 0 | my ($self, $attr) = @_; | |||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return unless ref $attr eq 'HASH'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 0 | my $cur = $self->{ attributes }; | |||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | 0 | for (keys %{$attr}) { | |||||||||||||||||||||||||||||||||
| 95 | 0 | $cur->{$_} = $attr->{$_}; | |||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | 0 | return; | |||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 1 | *replace_attribute = \&replace_attributes; | |||||||||||||||||||||||||||||||||
| 102 | 1 | *replace = \&replace_attributes; | |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub clear_attributes { | ||||||||||||||||||||||||||||||||
|
Subroutine
clear_attributes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 105 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 106 | 0 | $self->{ attributes } = { }; | |||||||||||||||||||||||||||||||||
| 107 | 0 | return; | |||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | 6 | ▶ | sub escape { | ||||||||||||||||||||||||||||||||
|
Subroutine
escape: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 112 | 6 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||
| 113 | 6 | for ($text) { | |||||||||||||||||||||||||||||||||
| 114 | 6 | s/&/&/g; | |||||||||||||||||||||||||||||||||
| 115 | 6 | s/</</g; | |||||||||||||||||||||||||||||||||
| 116 | 6 | s/>/>/g; | |||||||||||||||||||||||||||||||||
| 117 | 6 | s/"/"/g; | |||||||||||||||||||||||||||||||||
| 118 | 6 | s/'/'/g; | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | 6 | $text; | |||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | sub url { | ||||||||||||||||||||||||||||||||
|
Subroutine
url: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 124 | 1 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | return undef unless defined $text; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 126 | 1 | $text =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; | |||||||||||||||||||||||||||||||||
| 127 | 1 | return $text; | |||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||||||||