NAME
Tags::HTML - Tags helper abstract class.
SYNOPSIS
use Tags::HTML;
my $obj = Tags::HTML->new(%params);
$obj->cleanup(@params);
my $css_src_ar = $obj->css_src($css_link_ar);
$obj->init(@params);
my $script_js_ar = $obj->script_js($js_code_ar);
my $script_js_src_ar = $obj->script_js_src($js_link_ar);
$obj->prepare(@params);
$obj->process;
$obj->process_css;
METHODS
new
my $obj = Tags::HTML->new(%params);
Constructor.
Returns instance of class.
css
'CSS::Struct::Output' object for "process_css" processing.
Default value is undef.
no_css
No CSS support flag. If this flag is set to 1, "process_css" don't process CSS style.
Default value is 0.
tags
'Tags::Output' object for "process" processing.
Default value is undef.
cleanup
$obj->cleanup(@params);
Process cleanup after page run.
Returns undef.
css_src
my $css_src_ar = $obj->css_src($css_link_ar);
Add CSS link to object.
$css_link_ar
is reference to array of hashes with CSS information. CSS information is reference to hash with 'media' and 'link' keys.
Returns actual reference to array with CSS link info.
init
$obj->init(@params);
Process initialization in page run. It's useful in e.g. Plack::App::Tags::HTML.
Returns undef.
script_js
my $script_js_ar = $obj->script_js($js_code_ar);
Set/Get Javascript code array to object.
Returns reference to array with strings.
script_js_src
my $script_js_src_ar = $obj->script_js_src($js_link_ar);
Set/Get Javascript script link array to object.
Returns reference to array with strings.
prepare
$obj->prepare(@params);
Process initialization before page run. It's useful in e.g. Plack::App::Tags::HTML.
Returns undef.
process
$obj->process;
Process Tags structure.
Returns undef.
process_css
$obj->process_css;
Process CSS::Struct structure.
Returns undef.
process_js
$obj->process_js;
Process structure.
Returns undef.
ERRORS
new():
From Class::Utils::set_params():
Unknown parameter '%s'.
Parameter 'css' must be a 'CSS::Struct::Output::*' class.
Parameter 'tags' must be a 'Tags::Output::*' class.
process():
Need to be implemented in inherited class in _process() method.
Parameter 'tags' isn't defined.
process_css():
Need to be implemented in inherited class in _process_css() method.
Parameter 'css' isn't defined.
EXAMPLE1
use strict;
use warnings;
package Foo;
use base qw(Tags::HTML);
sub new {
my ($class, @params) = @_;
# No CSS support.
push @params, 'no_css', 1;
my $self = $class->SUPER::new(@params);
# Object.
return $self;
}
sub _cleanup {
my $self = shift;
delete $self->{'_dynamic_data'};
delete $self->{'_static_data'};
return;
}
sub _init {
my ($self, @variables) = @_;
$self->{'_dynamic_data'} = \@variables;
return;
}
sub _prepare {
my ($self, @variables) = @_;
$self->{'_static_data'} = \@variables;
return;
}
sub _process {
my $self = shift;
$self->{'tags'}->put(
['b', 'div'],
);
foreach my $variable (@{$self->{'_static_data'}}) {
$self->{'tags'}->put(
['b', 'div'],
['a', 'class', 'static'],
['d', $variable],
['e', 'div'],
);
}
foreach my $variable (@{$self->{'_dynamic_data'}}) {
$self->{'tags'}->put(
['b', 'div'],
['a', 'class', 'dynamic'],
['d', $variable],
['e', 'div'],
);
}
$self->{'tags'}->put(
['e', 'div'],
);
return;
}
package main;
use Tags::Output::Indent;
# Object.
my $tags = Tags::Output::Indent->new;
my $obj = Foo->new(
'tags' => $tags,
);
# Init static data.
$obj->prepare('foo', 'bar');
# Init dynamic data.
$obj->init('baz', 'bax');
# Process.
$obj->process;
# Print out.
print "HTML\n";
print $tags->flush."\n";
# Output:
# HTML
# <div>
# <div class="static">
# foo
# </div>
# <div class="static">
# bar
# </div>
# <div class="dynamic">
# baz
# </div>
# <div class="dynamic">
# bax
# </div>
# </div>
EXAMPLE2
use strict;
use warnings;
package Foo;
use base qw(Tags::HTML);
sub _process {
my ($self, $value) = @_;
$self->{'tags'}->put(
['b', 'div'],
['d', $value],
['e', 'div'],
);
return;
}
sub _process_css {
my ($self, $color) = @_;
$self->{'css'}->put(
['s', 'div'],
['d', 'background-color', $color],
['e'],
);
return;
}
package main;
use CSS::Struct::Output::Indent;
use Tags::Output::Indent;
# Object.
my $css = CSS::Struct::Output::Indent->new;
my $tags = Tags::Output::Indent->new;
my $obj = Foo->new(
'css' => $css,
'tags' => $tags,
);
# Process indicator.
$obj->process_css('red');
$obj->process('value');
# Print out.
print "CSS\n";
print $css->flush."\n\n";
print "HTML\n";
print $tags->flush."\n";
# Output:
# CSS
# div {
# background-color: red;
# }
#
# HTML
# <div>
# value
# </div>
DEPENDENCIES
Class::Utils, Error::Pure, Scalar::Util.
SEE ALSO
- Plack::App::Tags::HTML
-
Plack application for Tags::HTML objects.
- Plack::Component::Tags::HTML
-
Plack component for Tags with HTML output.
REPOSITORY
https://github.com/michal-josef-spacek/Tags-HTML
AUTHOR
Michal Josef Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2021-2024 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.10