| 1 | package Tags::HTML::Messages; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use base qw(Tags::HTML); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Class::Utils qw(set_params split_params); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Mo::utils::Hash 0.02 qw(check_hash check_hash_keys); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Mo::utils::Language 0.05 qw(check_language_639_2); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | our $VERSION = 0.10; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # Constructor. | ||||||||||||||||||||||||||||
| 16 | 28 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 28 | my ($class, @params) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Create object. | ||||||||||||||||||||||||||||
| 20 | 28 | my ($object_params_ar, $other_params_ar) = split_params( | |||||||||||||||||||||||||||
| 21 | ['css_messages', 'flag_no_messages', 'lang', 'text'], @params); | ||||||||||||||||||||||||||||
| 22 | 28 | my $self = $class->SUPER::new(@{$other_params_ar}); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # CSS class. | ||||||||||||||||||||||||||||
| 25 | 26 | $self->{'css_messages'} = 'messages'; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Flag for no messages. | ||||||||||||||||||||||||||||
| 28 | 26 | $self->{'flag_no_messages'} = 1; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Language. | ||||||||||||||||||||||||||||
| 31 | 26 | $self->{'lang'} = 'eng'; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # Texts. | ||||||||||||||||||||||||||||
| 34 | 26 | $self->{'text'} = { | |||||||||||||||||||||||||||
| 35 | 'eng' => { | ||||||||||||||||||||||||||||
| 36 | 'no_messages' => 'No messages', | ||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Process params. | ||||||||||||||||||||||||||||
| 41 | 26 | set_params($self, @{$object_params_ar}); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Check language. | ||||||||||||||||||||||||||||
| 44 | 26 | check_language_639_2($self, 'lang'); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # Check texts. | ||||||||||||||||||||||||||||
| 47 | 25 | check_hash($self, 'text'); | |||||||||||||||||||||||||||
| 48 | 24 | check_hash_keys($self, 'text', $self->{'lang'}); | |||||||||||||||||||||||||||
| 49 | 23 | check_hash_keys($self, 'text', $self->{'lang'}, 'no_messages'); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # Object. | ||||||||||||||||||||||||||||
| 52 | 22 | return $self; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 11 | ▶ | sub _check_messages { | ||||||||||||||||||||||||||
|
Subroutine
_check_messages: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 56 | 11 | my ($self, $message_ar) = @_; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 11 | ▶ | if (ref $message_ar ne 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 1 | err "Bad list of messages."; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 10 | foreach my $message (@{$message_ar}) { | |||||||||||||||||||||||||||
| 62 | 8 | ▶ | if (! blessed($message) || ! $message->isa('Data::Message::Simple')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($message) and $message->isa("Data::Message::Simple")
MC/DC100%2/2
builtin::blessed($message) and $message->isa("Data::Message::Simple")
builtin::blessed($message)
$message->isa("Data::Message::Simple")
Truth table100%3/3
A and B
A= builtin::blessed($message)B= $message->isa("Data::Message::Simple")
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | err 'Bad message data object.'; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 8 | return; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Process 'Tags'. | ||||||||||||||||||||||||||||
| 72 | 12 | ▶ | sub _process { | ||||||||||||||||||||||||||
|
Subroutine
_process: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 73 | 12 | my ($self, $message_ar) = @_; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 12 | ▶ | if (! defined $message_ar) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 1 | return; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 11 | $self->_check_messages($message_ar); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # No messages. | ||||||||||||||||||||||||||||
| 82 | 8 | ▶ | if (! $self->{'flag_no_messages'} && ! @{$message_ar}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"flag_no_messages"} or @{$message_ar;}
MC/DC100%2/2
$self->{"flag_no_messages"} or @{$message_ar;}
$self->{"flag_no_messages"}
@{$message_ar;}
Truth table100%3/3
A or B
A= $self->{"flag_no_messages"}B= @{$message_ar;}
| |||||||||||||||||||||||||||||
| 83 | 1 | return; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 7 | my $num = 0; | |||||||||||||||||||||||||||
| 87 | $self->{'tags'}->put( | ||||||||||||||||||||||||||||
| 88 | ['b', 'div'], | ||||||||||||||||||||||||||||
| 89 | 7 | ['a', 'class', $self->{'css_messages'}], | |||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||
| 91 | 7 | ▶ | if (@{$message_ar}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 5 | foreach my $message (@{$message_ar}) { | |||||||||||||||||||||||||||
| 93 | 6 | ▶ | if ($num) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 1 | $self->{'tags'}->put( | |||||||||||||||||||||||||||
| 95 | ['b', 'br'], | ||||||||||||||||||||||||||||
| 96 | ['e', 'br'], | ||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 6 | ▶ | $self->{'tags'}->put( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | ['b', 'span'], | ||||||||||||||||||||||||||||
| 101 | ['a', 'class', $message->type], | ||||||||||||||||||||||||||||
| 102 | defined $message->lang | ||||||||||||||||||||||||||||
| 103 | ? (['a', 'lang', $message->lang]) | ||||||||||||||||||||||||||||
| 104 | : (), | ||||||||||||||||||||||||||||
| 105 | ['d', $message->text], | ||||||||||||||||||||||||||||
| 106 | ['e', 'span'], | ||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||
| 108 | 6 | $num++; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } else { | ||||||||||||||||||||||||||||
| 111 | $self->{'tags'}->put( | ||||||||||||||||||||||||||||
| 112 | 2 | ['d', $self->{'text'}->{$self->{'lang'}}->{'no_messages'}], | |||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 7 | $self->{'tags'}->put( | |||||||||||||||||||||||||||
| 116 | ['e', 'div'], | ||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 7 | return; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # Process 'CSS::Struct'. | ||||||||||||||||||||||||||||
| 123 | 4 | ▶ | sub _process_css { | ||||||||||||||||||||||||||
|
Subroutine
_process_css: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 124 | 4 | my ($self, $message_types_hr) = @_; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 4 | ▶ | if (! defined $message_types_hr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 1 | return; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 3 | ▶ | if (ref $message_types_hr ne 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 1 | err 'Message types must be a hash reference.'; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 2 | foreach my $message_type (sort keys %{$message_types_hr}) { | |||||||||||||||||||||||||||
| 134 | $self->{'css'}->put( | ||||||||||||||||||||||||||||
| 135 | ['s', '.'.$message_type], | ||||||||||||||||||||||||||||
| 136 | 1 | ['d', 'color', $message_types_hr->{$message_type}], | |||||||||||||||||||||||||||
| 137 | ['e'], | ||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | return; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 5 | 1; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||