| 1 | package HTML::GUI::tag; | ||||||||||
| 2 | |||||||||||
| 3 | 14 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 14 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | HTML::GUI::tag - generate html tags | ||||||||||
| 9 | |||||||||||
| 10 | =head1 VERSION | ||||||||||
| 11 | |||||||||||
| 12 | Version 0.01 | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | |||||||||||
| 16 | 14 | our $VERSION = '0.01'; | |||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | =head1 TAG | ||||||||||
| 21 | |||||||||||
| 22 | abstract class for generating html. | ||||||||||
| 23 | |||||||||||
| 24 | =cut | ||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | =pod | ||||||||||
| 29 | |||||||||||
| 30 | =head1 PUBLIC METHODS | ||||||||||
| 31 | |||||||||||
| 32 | =pod | ||||||||||
| 33 | |||||||||||
| 34 | =head3 new | ||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | =cut | ||||||||||
| 38 | |||||||||||
| 39 | sub new | ||||||||||
| 40 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 41 | 0 | my($class | |||||||||
| 42 | ) = @_; | ||||||||||
| 43 | |||||||||||
| 44 | 0 | my $this = {}; | |||||||||
| 45 | |||||||||||
| 46 | 0 | bless($this, $class); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | =head3 escapeHtml | ||||||||||
| 52 | |||||||||||
| 53 | Description : | ||||||||||
| 54 | return the protected label with : | ||||||||||
| 55 | - " instead of " | ||||||||||
| 56 | - & insterad of & | ||||||||||
| 57 | |||||||||||
| 58 | =cut | ||||||||||
| 59 | 0 | ▶ | sub escapeHtml($$){ | ||||||||
|
Subroutine
escapeHtml: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 60 | 0 | my ($self,$label)=@_; | |||||||||
| 61 | 0 | $label =~ s/&/&/g; | |||||||||
| 62 | 0 | $label =~ s/"/"/g; | |||||||||
| 63 | 0 | $label =~ s/</</g; | |||||||||
| 64 | 0 | $label =~ s/>/>/g; | |||||||||
| 65 | 0 | return $label | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | =pod | ||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | =head3 getHtmlTag | ||||||||||
| 72 | |||||||||||
| 73 | Parameters : | ||||||||||
| 74 | tagName : string : Name of the tag to generate | ||||||||||
| 75 | @htmlProperties : array : Array of hash ref of properties for the tag (propName => propValue) | ||||||||||
| 76 | content : string : Content of the HTML tag. The content string is inserted "as is" in the tag, it should not contain special characters like '&' or '<' except for coding entities or inner tags. | ||||||||||
| 77 | |||||||||||
| 78 | |||||||||||
| 79 | Return : | ||||||||||
| 80 | string | ||||||||||
| 81 | |||||||||||
| 82 | Description : | ||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | =cut | ||||||||||
| 86 | |||||||||||
| 87 | sub getHtmlTag | ||||||||||
| 88 | 0 | ▶ | { | ||||||||
|
Subroutine
getHtmlTag: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 89 | 0 | my($self, | |||||||||
| 90 | $tagName, # string : Name of the tag to generate | ||||||||||
| 91 | $tagProperties, # array : hash ref of properties for the tag (propName => propValue) | ||||||||||
| 92 | $content, # string : Content of the HTML tag. | ||||||||||
| 93 | |||||||||||
| 94 | ) = @_; | ||||||||||
| 95 | 0 | my @widgetProp = (); | |||||||||
| 96 | 0 | my @propNames = (); | |||||||||
| 97 | 0 | @propNames = keys %$tagProperties; | |||||||||
| 98 | 0 | @propNames = sort {$a cmp $b} @propNames; #always the same order | |||||||||
| 99 | 0 | foreach my $propName (@propNames){ | |||||||||
| 100 | 0 | ▶ | if ($tagProperties->{$propName} ne ""){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | push @widgetProp, | ||||||||||
| 102 | 0 | $propName.'="'.$self->escapeHtml($tagProperties->{$propName}).'"'; | |||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | } | ||||||||||
| 106 | 0 | my $tagHtml = join ' ',$tagName,@widgetProp; | |||||||||
| 107 | 0 | ▶ | if ($content){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 0 | return '<'.$tagHtml.'>' | |||||||||
| 109 | .$content | ||||||||||
| 110 | .'</'.$tagName.'>'; | ||||||||||
| 111 | }else{ | ||||||||||
| 112 | 0 | return '<'.$tagHtml.'/>'; | |||||||||
| 113 | |||||||||||
| 114 | } | ||||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | =head1 AUTHOR | ||||||||||
| 118 | |||||||||||
| 119 | Jean-Christian Hassler, C<< <jhassler at free.fr> >> | ||||||||||
| 120 | |||||||||||
| 121 | =head1 BUGS | ||||||||||
| 122 | |||||||||||
| 123 | Please report any bugs or feature requests to | ||||||||||
| 124 | C<bug-gui-libhtml-tag at rt.cpan.org>, or through the web interface at | ||||||||||
| 125 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-GUI>. | ||||||||||
| 126 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||
| 127 | your bug as I make changes. | ||||||||||
| 128 | |||||||||||
| 129 | =head1 SUPPORT | ||||||||||
| 130 | |||||||||||
| 131 | You can find documentation for this module with the perldoc command. | ||||||||||
| 132 | |||||||||||
| 133 | perldoc HTML::GUI::widget | ||||||||||
| 134 | |||||||||||
| 135 | You can also look for information at: | ||||||||||
| 136 | |||||||||||
| 137 | =over 4 | ||||||||||
| 138 | |||||||||||
| 139 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 140 | |||||||||||
| 141 | L<http://annocpan.org/dist/HTML-GUI> | ||||||||||
| 142 | |||||||||||
| 143 | =item * CPAN Ratings | ||||||||||
| 144 | |||||||||||
| 145 | L<http://cpanratings.perl.org/d/HTML-GUI> | ||||||||||
| 146 | |||||||||||
| 147 | =item * RT: CPAN's request tracker | ||||||||||
| 148 | |||||||||||
| 149 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-GUI> | ||||||||||
| 150 | |||||||||||
| 151 | =item * Search CPAN | ||||||||||
| 152 | |||||||||||
| 153 | L<http://search.cpan.org/dist/HTML-GUI> | ||||||||||
| 154 | |||||||||||
| 155 | =back | ||||||||||
| 156 | |||||||||||
| 157 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 158 | |||||||||||
| 159 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 160 | |||||||||||
| 161 | Copyright 2007 Jean-Christian Hassler, all rights reserved. | ||||||||||
| 162 | |||||||||||
| 163 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 164 | under the same terms as Perl itself. | ||||||||||
| 165 | |||||||||||
| 166 | =cut | ||||||||||
| 167 | |||||||||||
| 168 | 14 | 1; # End of HTML::GUI::tag | |||||||||