|
NAMEText::Colorizer - Create colored text from text and color descrition. An ANSI to HTML tranformation is provided SYNOPSIS my $c= Text::Colorizer->new
(
NAME => '' ,
INTERACTION =>
{
INFO => sub {print @_},
WARN => \&Carp::carp,
DIE => \&Carp::confess,
}
FORMAT => 'HTML' | 'ANSI' |'ASCII',
DEFAULT_COLOR => 'bright_white on_black',
COLOR_NAMES =>
{
HTML =>
{
white => "color:#888;",
black => "color:#000;",
...
}
ANSI => ...
ASCII => ...
}
) ;
# or
my $c= Text::Colorizer->new() ;
my $colored_text = $c->color
(
'red on_black' => 'string',
$color => [... many strings..],
'user_defined_color_name' => 'string'
) ;
DESCRIPTIONThis module defined methods to produce colored html from ANSI color description. The generated code use pre tags. The generated HTML can be embeded in your pod documentation. DOCUMENTATIONValid colors: black red green yellow blue magenta cyan white bright_black bright_red bright_green bright_yellow bright_blue bright_magenta bright_cyan bright_white on_black on_red on_green on yellow on_blue on_magenta on_cyan on_white on_bright_black on_bright_red on_bright_green on_bright_yellow on_bright_blue on_bright_magenta on_bright_cyan on_bright_white Default background colorbright_white on_black SUBROUTINES/METHODSnew(NAMED_ARGUMENTS)Create a Text::Colorizer object. my $c= Text::Colorizer->new() ; Arguments - a list of pairs - Option => Value
Returns - Text::Colorizer Exceptions - Dies if the color description are not valid SetupHelper sub called by new. This is a private sub. CheckOptionNamesVerifies the named options passed to the members of this class. Calls {INTERACTION}{DIE} in case of error. This shall not be used directly. get_colors( )Returns the colors defined in the object my $colors = $c->get_colors( ) ; Arguments - None Returns - A hash reference Exceptions - None set_colors(\%colors)Copies my %colors =
(
HTML =>
{
white => "style='color:#888;'",
black => "style='color:#000;'",
...
bright_white => "style='color:#fff;'",
bright_black => "style='color:#000;'",
bright_green => "style='color:#0f0;'",
...
}
) ;
$c->set_color(\%colors) ;
Arguments
Returns - Nothing Exceptions - dies if the color definitions are invalid [P] flatten($scalar || \@array)Transforms array references to a flat list Arguments -
Returns - a lsit of scalars color($color_name, $text, $color_name, \@many_text_strings, ...) ;Returns colored text. according to the object setting. Default is HTML color coded. my $colored_text = $c->color
(
'red on_black' => 'string',
$color => [... many strings..]
'user_defined_color_name' => 'string'
) ;
Arguments - A list of colors and text pairs
Returns - A single string Exceptions - Dies if the color is invalid color_all($color, $string, \@many_text_strings, ...)Uses a single color to colorize all the strings my $colored_text = $c->color_all($color, $string, \@many_text_strings, ...) ; Arguments
Returns - Nothing Exceptions color_with(\%color_definitions, 'color' => 'text', $color => \@many_text_strings, ...) ;Colors a text, temporarely overridding the colors defined in the object. my %colors =
{
HTML =>
{
white => "style='color:#888;'",
black => "style='color:#000;'",
...
bright_white => "style='color:#fff;'",
bright_black => "style='color:#000;'",
bright_green => "style='color:#0f0;'",
...
}
},
my $colored_text = $c->color
(
'red on_black' => 'string',
'blue on_yellow' => [... many strings..]
'user_defined_color_name' => 'string'
) ;
Arguments
Returns - Nothing Exceptions - Dies if any argument is invalid color_all_with($temporary_colors, $color, $text | \@many_text_string, ...) ;Uses a single color to colorize all the strings, using a temporary color definition my $temporary_colors =
{
HTML =>
{
white => "style='color:#888;'",
black => "style='color:#000;'",
...
bright_white => "style='color:#fff;'",
bright_black => "style='color:#000;'",
bright_green => "style='color:#0f0;'",
...
}
},
my $colored_text = $c->color_all_with($temporary_colors, $color, 'string', [... many strings..], ...) ;
Arguments
Returns - A colorized string Exceptions Dies if invalid input is received BUGS AND LIMITATIONSNone so far. AUTHOR Nadim ibn hamouda el Khemir
CPAN ID: NKH
mailto: nadim@cpan.org
COPYRIGHT AND LICENSECopyright 2010 Nadim Khemir. This program is free software; you can redistribute it and/or modify it under the terms of either:
SUPPORTYou can find documentation for this module with the perldoc command. perldoc Text::Colorizer You can also look for information at:
SEE ALSO"HTML::FromANSI first"
|