Tags::HTML::Messages - Tags helper for HTML messages.
use Tags::HTML::Messages; my $obj = Tags::HTML::Messages->new(%params); $obj->process($message_ar); $obj->process_css($type, $color);
new
my $obj = Tags::HTML::Messages->new(%params);
Constructor.
css
'CSS::Struct::Output' object for process_css processing.
Default value is undef.
css_messages
CSS class for main messages div block.
Default value is 'messages'.
flag_no_messages
Flag for no messages printing.
Possible values:
0 - Print nothing 1 - Print message box with 'No messages.' text.
Default value is 1.
tags
'Tags::Output' object.
process
$obj->process($message_ar);
Process Tags structure for output.
Reference to array with message objects $message_ar must be a instance of Data::Message::Simple object.
$message_ar
Returns undef.
process_css
$obj->process_css($message_types_hr);
Process CSS::Struct structure for output.
Variable $message_type_hr is reference to hash with keys for message type and value for color in CSS style. Possible message types are info and error now. Types are defined in Data::Message::Simple.
$message_type_hr
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(): Bad list of messages. Bad message data object. process_css(): Message types must be a hash reference.
use strict; use warnings; use CSS::Struct::Output::Indent; use Data::Message::Simple; use Tags::HTML::Page::Begin; use Tags::HTML::Page::End; use Tags::HTML::Messages; use Tags::Output::Indent; # Object. my $tags = Tags::Output::Indent->new( 'preserved' => ['style'], 'xml' => 1, ); my $css = CSS::Struct::Output::Indent->new; my $begin = Tags::HTML::Page::Begin->new( 'css' => $css, 'lang' => { 'title' => 'Tags::HTML::Messages example', }, 'generator' => 'Tags::HTML::Messages', 'tags' => $tags, ); my $end = Tags::HTML::Page::End->new( 'tags' => $tags, ); my $messages = Tags::HTML::Messages->new( 'css' => $css, 'tags' => $tags, ); # Error structure. my $message_ar = [ Data::Message::Simple->new( 'text' => 'Error #1', 'type' => 'error', ), Data::Message::Simple->new( 'text' => 'Error #2', 'type' => 'error', ), Data::Message::Simple->new( 'lang' => 'en', 'text' => 'Ok #1', ), Data::Message::Simple->new( 'text' => 'Ok #2', ), ]; # Process page. $messages->process_css({ 'error' => 'red', 'info' => 'green', }); $begin->process; $messages->process($message_ar); $end->process; # Print out. print $tags->flush; # Output: # <!DOCTYPE html> # <html lang="en"> # <head> # <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> # <meta name="generator" content="Tags::HTML::Messages" /> # <meta name="viewport" content="width=device-width, initial-scale=1.0" /> # <title> # Tags::HTML::Messages example # </title> # <style type="text/css"> # .error { # color: red; # } # .info { # color: green; # } # </style> # </head> # <body> # <div class="messages"> # <span class="error"> # Error #1 # </span> # <br /> # <span class="error"> # Error #2 # </span> # <br /> # <span class="info" lang="en"> # Ok #1 # </span> # <br /> # <span class="info"> # Ok #2 # </span> # </div> # </body> # </html>
Class::Utils, Error::Pure, Scalar::Util, Tags::HTML.
https://github.com/michal-josef-spacek/Tags-HTML-Messages
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© Michal Josef Špaček 2020-2023
BSD 2-Clause License
0.09
To install Tags::HTML::Messages, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tags::HTML::Messages
CPAN shell
perl -MCPAN -e shell install Tags::HTML::Messages
For more information on module installation, please visit the detailed CPAN module installation guide.