NAME
Plack::App::Tags::HTML - Plack application for running Tags::HTML objects.
SYNOPSIS
use Plack::App::Tags::HTML;
my $obj = Plack::App::Tags::HTML->new(%parameters);
my $app = $obj->to_app;
METHODS
Class inherites Plack::Component::Tags::HTML.
new
my $obj = Plack::App::Tags::HTML->new(%parameters);
Constructor.
Returns instance of object.
component
Tags::HTML component.
Option is required.
constructor_args
Tags::HTML component constructor arguments.
Default value is undef.
data
Array data structure as input argument of Tags::HTML::process().
Default value is undef.
data_css
Reference to array with structure for input argument of Tags::HTML::process_css().
Default value is undef.
data_init
Reference to array with structure for input argument of Tags::HTML::init().
This structure is used in init phase of each web app call.
Default value is undef.
data_prepare
Reference to array with structure for input argument of Tags::HTML::prepare().
This structure is used in prepare phase of web app run.
Default value is undef.
to_app
my $app = $obj->to_app;
Get code of plack application.
Returns code of app.
ERRORS
prepare_app():
Cannot load component '%s'.
Error: %s
Component must be a instance of 'Tags::HTML' class.
EXAMPLE1
use strict;
use warnings;
use CSS::Struct::Output::Indent;
use Plack::App::Tags::HTML;
use Plack::Runner;
use Tags::Output::Indent;
# Run application.
my $app = Plack::App::Tags::HTML->new(
'component' => 'Tags::HTML::Stars',
'css' => CSS::Struct::Output::Indent->new,,
'data' => [{
1 => 'full',
2 => 'half',
3 => 'nothing',
}],
'tags' => Tags::Output::Indent->new(
'preserved' => ['style'],
),
)->to_app;
Plack::Runner->new->run($app);
# Output:
# HTTP::Server::PSGI: Accepting connections at http://0:5000/
# > curl http://localhost:5000/
# <!DOCTYPE html>
# <html lang="en">
# <head>
# <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
# </meta>
# <meta name="viewport" content="width=device-width, initial-scale=1.0">
# </meta>
# <style type="text/css">
# * {
# box-sizing: border-box;
# margin: 0;
# padding: 0;
# }
# </style>
# </head>
# <body>
# <div>
# <img src=
# "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAwcHgiIGhlaWdodD0iMjc1cHgiIHZpZXdCb3g9IjAgMCAzMDAgMjc1I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MSAxOTcsMTY1IDIyMywyNTEgMTUwLDIwMCA3NywyNTEgMTAzLDE2NSAzMSwxMTEgMTIxLDExMSIgY2xpcC1wYXRoPSJ1cmwoI2ZpbGxlZCkiIC8+Cjwvc3ZnPgo="
# >
# </img>
# <img src=
# "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAwcHgiIGhlaWdodD0iMjc1cHgiIHZpZXdCb3g9IjAgMCAzMDAgMjc1IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSI+CiAgPHBvbHlnb24gZmlsbD0ibm9uZSIgc3Ryb2tlPSIjODA4MDgwIiBzdHJva2Utd2lkdGg9IjE1IiBzdHJva2Utb3BhY2l0eT0iMC4zNzY0NzA2MCIgcG9pbnRzPSIxNTAsMjUgMTc5LDExMSAyNjksMTExIDE5NywxNjUgMjIzLDI1MSAxNTAsMjAwIDc3LDI1MSAxMDMsMTY1IDMxLDExMSAxMjEsMTExIiAvPgo8L3N2Zz4K"
# >
# </img>
# </div>
# </body>
# </html>
EXAMPLE2
use strict;
use warnings;
package App;
use base qw(Tags::HTML);
sub _process {
my ($self, $value_hr) = @_;
$self->{'tags'}->put(
['b', 'div'],
['a', 'class', 'my-class'],
['d', join ',', @{$value_hr->{'foo'}}],
['e', 'div'],
);
return;
}
sub _process_css {
my $self = shift;
$self->{'css'}->put(
['s', '.my-class'],
['d', 'border', '1px solid black'],
['e'],
);
return;
}
package main;
use CSS::Struct::Output::Indent;
use Plack::App::Tags::HTML;
use Plack::Runner;
use Tags::Output::Indent;
# Run application.
my $app = Plack::App::Tags::HTML->new(
'component' => 'App',
'css' => CSS::Struct::Output::Indent->new,
'data' => [{
'foo' => [1, 2],
}],
'tags' => Tags::Output::Indent->new(
'preserved' => ['style'],
),
)->to_app;
Plack::Runner->new->run($app);
# Output:
# HTTP::Server::PSGI: Accepting connections at http://0:5000/
# > curl http://localhost:5000/
# <!DOCTYPE html>
# <html lang="en">
# <head>
# <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
# </meta>
# <meta name="viewport" content="width=device-width, initial-scale=1.0">
# </meta>
# <style type="text/css">
# * {
# box-sizing: border-box;
# margin: 0;
# padding: 0;
# }
# .my-class {
# border: 1px solid black;
# }
# </style>
# </head>
# <body>
# <div class="my-class">
# 1,2
# </div>
# </body>
# </html>
DEPENDENCIES
English, Error::Pure, Plack::Component::Tags::HTML, Plack::Util::Accessor, Symbol::Get.
SEE ALSO
- Tags::HTML
-
Tags helper abstract class.
REPOSITORY
https://github.com/michal-josef-spacek/Plack-App-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.17