Quiq/Html/HorizontalMenu.pm

filter: Statementstmt 42.1% 16 / 38 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 37.7% 23 / 61 CC 8 SCAR 33.7
CC
8
Cov
33%
html
56.0
new
6.0
BEGIN
1.0
CRAP 29.2
« Quiq/JQuery/MenuBar.pm ↑ Summary Quiq/Program.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Html::HorizontalMenu - Einfaches horizontales Menü
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Ein Objekt der Klasse repräsentiert ein horizontales Menü
16 zur Auswahl von Links.
17  
18 =head1 ATTRIBUTES
19  
20 =over 4
21  
22 =item active => $name
23  
24 Der Name oder das Label des ausgewählten Menüelements.
25  
26 =item class => $class
27  
28 CSS-Klasse.
29  
30 =item id => $id
31  
32 CSS-Id des Menüs.
33  
34 =item items => \@items
35  
36 Die Elemente des Menüs. Struktur eines Menüelements:
37  
38 {
39 name => $name,
40 class => undef,
41 label => $label,
42 url => $url,
43 }
44  
45 =item style => $style
46  
47 CSS-Style.
48  
49 =back
50  
51 =cut
52  
53 # -----------------------------------------------------------------------------
54  
55 package Quiq::Html::HorizontalMenu;
56 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 1 our $VERSION = '1.240';
63  
64 1 ▶use Quiq::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 # -----------------------------------------------------------------------------
67  
68 =head1 METHODS
69  
70 =head2 Konstruktor
71  
72 =head3 new() - Instantiiere Menü-Objekt
73  
74 =head4 Synopsis
75  
76 $e = $class->new(@keyVal);
77  
78 =head4 Arguments
79  
80 =over 4
81  
82 =item @keyVal
83  
84 Liste von Attribut/Wert-Paaren. Die Werte werden auf dem Objekt
85 gesetzt. Siehe Abschnitt ATTRIBUTES.
86  
87 =back
88  
89 =head4 Returns
90  
91 =over 4
92  
93 =item $e
94  
95 Menü-Objekt
96  
97 =back
98  
99 =head4 Description
100  
101 Instantiiere ein Menü-Objekt und liefere eine Referenz auf
102 dieses Objekt zurück.
103  
104 =cut
105  
106 # -----------------------------------------------------------------------------
107  
108 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
109 0 my $class = shift;
110 # @_: @keyVal
111  
112 0 my $self = $class->SUPER::new(
113 active => undef,
114 class => undef,
115 id => undef,
116 items => [],
117 style => undef,
118 );
119 0 $self->set(@_);
120  
121 0 my @items;
122 0 for (@{$self->items}) {
123 0 push @items,Quiq::Hash->new($_,
124 name => undef,
125 class => undef,
126 label => undef,
127 url => undef,
128 );
129 }
130 0 $self->items(\@items);
131  
132 0 return $self;
133 }
134  
135 # -----------------------------------------------------------------------------
136  
137 =head2 Objektmethoden
138  
139 =head3 html() - Generiere HTML-Code
140  
141 =head4 Synopsis
142  
143 $html = $e->html($h);
144 $html = $class->html($h,@keyVal);
145  
146 =head4 Arguments
147  
148 =over 4
149  
150 =item $h
151  
152 Objekt für die HTML-Generierung, d.h. eine Instanz der Klasse
153 Quiq::Html::Tag.
154  
155 =item @keyVal
156  
157 Siehe Konstruktor.
158  
159 =back
160  
161 =head4 Returns
162  
163 HTML-Code (String)
164  
165 =head4 Description
166  
167 Generiere den HTML-Code des Menüs und liefere diesen
168 zurück. Als Klassenmethode gerufen, wird das Objekt intern
169 mit den Attributen @keyVal instantiiert.
170  
171 =cut
172  
173 # -----------------------------------------------------------------------------
174  
175 0 ▶sub html {
Subroutine html: not called CC=7 SCAR=40.3
Pod documented
176 0 my $this = shift;
177 0 my $h = shift;
178 # @_: @keyVal
179  
180 0 ▶ my $self = ref $this? $this: $this->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 0 0 0
181  
182 0 my ($active,$cssClass,$id,$itemA,$style) =
183 $self->get(qw/active class id items style/);
184 0 ▶ $active //= '';
Condition0%0/2
$active //= ""
l!l
00
MC/DC0%0/1
$active //= ""
$active
Truth table0%0/2
A
A= $active
Aresult
11
00
185  
186 0 my $html = '';
187 0 for my $itm (@$itemA) {
188 0 ▶ if ($html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html) 0 0 0
189 0 $html .= ' | ';
190 }
191  
192 0 ▶ $html .= $h->tag('a',
Condition0%0/3
$itm->name // $itm->label
l!l&&r!l&&!r
000
MC/DC0%0/2
$itm->name // $itm->label
$itm->name $itm->label
Truth table0%0/3
A // B
A= $itm->nameB= $itm->label
ABresult
1X1
011
000
193 -ignoreTagIf => ($itm->name // $itm->label) eq $active,
194 class => $itm->class,
195 href => $itm->url,
196 $itm->label
197 );
198 }
199 0 ▶ if ($html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html) 0 0 0
200 0 $html = $h->tag('div',
201 class => $cssClass,
202 id => $id,
203 style => $style,
204 "[ $html ]"
205 );
206 }
207  
208 0 return $html;
209 }
210  
211 # -----------------------------------------------------------------------------
212  
213 =head1 VERSION
214  
215 1.240
216  
217 =head1 AUTHOR
218  
219 Frank Seitz, L<http://fseitz.de/>
220  
221 =head1 COPYRIGHT
222  
223 Copyright (C) 2026 Frank Seitz
224  
225 =head1 LICENSE
226  
227 This code is free software; you can redistribute it and/or modify
228 it under the same terms as Perl itself.
229  
230 =cut
231  
232 # -----------------------------------------------------------------------------
233  
234 1 1;
235  
236 # eof
« Quiq/JQuery/MenuBar.pm ↑ Summary Quiq/Program.pm »