Quiq/Html/Resources.pm

filter: Statementstmt 95.8% 23 / 24 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 92.1% 35 / 38 CC 6 SCAR 13.6
CC
6
Cov
90%
resources
6.3
BEGIN
1.0
BEGIN
1.0
CRAP 3.9
« Quiq/Confluence/Page.pm ↑ Summary Quiq/TempFile.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Html::Resources - CSS- und JavaScript-Resourcen einer Webapplikation
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Ein Objekt der Klasse ist ein Speicher für die Definition von CSS- und
16 JavaScript-Ressourcen. Die Ressourcen werden unter einem Schlüssel
17 $key, z.B. 'jquery' oder 'jquery-ui', im Speicher abgelegt und
18 nach ihrem Typ (css, js) unterschieden.
19  
20 =head1 EXAMPLE
21  
22 use Quiq::Html::Resources;
23
24 # Instantiiere Objekt (hier am Beispiel der Resourcen 'jquery'
25 # und 'jquery-ui')
26
27 my $res = Quiq::Html::Resources->new(
28 jquery => {
29 js => [
30 'https://code.jquery.com/jquery-latest.min.js',
31 ],
32 },
33 'jquery-ui' => {
34 css => [
35 'https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css',
36 ],
37 js => [
38 'https://code.jquery.com/ui/1.12.1/jquery-ui.min.js',
39 ],
40 },
41 );
42
43 my @cssResources = $res->resources('jquery-ui','css');
44 # ('https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css')
45
46 my @jsResources = $res->resources('jquery-ui','js');
47 # ('https://code.jquery.com/ui/1.12.1/jquery-ui.css')
48  
49 =cut
50  
51 # -----------------------------------------------------------------------------
52  
53 package Quiq::Html::Resources;
54 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 1 our $VERSION = '1.240';
61  
62 # -----------------------------------------------------------------------------
63  
64 =head1 METHODS
65  
66 =head2 Konstruktor
67  
68 =head3 new() - Instantiiere Objekt
69  
70 =head4 Synopsis
71  
72 $res = $class->new($key=>\%typeArr,...);
73  
74 =head4 Description
75  
76 Instantiiere ein Objekt der Klasse und liefere eine Referenz auf
77 dieses Objekt zurück.
78  
79 =cut
80  
81 # -----------------------------------------------------------------------------
82  
83 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
84 1 my $class = shift;
85 # @_: $key=>\%typeArr,...
86 1 return $class->SUPER::new({@_});
87 }
88  
89 # -----------------------------------------------------------------------------
90  
91 =head2 Objektmethoden
92  
93 =head3 resources() - Liefere Liste von Ressourcen
94  
95 =head4 Synopsis
96  
97 @arr | $arr = $res->resources(@keys);
98  
99 =head4 Arguments
100  
101 =over 4
102  
103 =item @keys
104  
105 Liste von Schlüsseln, z.B. 'jquery', 'datatables'.
106  
107 =back
108  
109 =head4 Description
110  
111 Liefere die Liste der Ressourcen zu den Schlüsseln @keys.
112  
113 =cut
114  
115 # -----------------------------------------------------------------------------
116  
117 1 ▶sub resources {
Subroutine resources: called CC=6 SCAR=18.4
Pod documented
118 1 my $self = shift;
119 # @_: @keys
120  
121 1 my @arr;
122 1 for my $key (@_) {
123 2 ▶ if (!exists $self->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{$key}) 0 2 2
124 0 $self->throw(
125 'RESOURCE-00001: Resource not defined',
126 Resource => $key,
127 );
128 }
129 2 for my $type ('css','js') {
130 4 ▶ if (my $arr = $self->{$key}->{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $arr = $self->{$key}{$type}) 3 1 4
131 3 push @arr,@$arr;
132 }
133 }
134 }
135  
136 1 ▶ return wantarray? @arr: \@arr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
137 }
138  
139 # -----------------------------------------------------------------------------
140  
141 =head1 VERSION
142  
143 1.240
144  
145 =head1 AUTHOR
146  
147 Frank Seitz, L<http://fseitz.de/>
148  
149 =head1 COPYRIGHT
150  
151 Copyright (C) 2026 Frank Seitz
152  
153 =head1 LICENSE
154  
155 This code is free software; you can redistribute it and/or modify
156 it under the same terms as Perl itself.
157  
158 =cut
159  
160 # -----------------------------------------------------------------------------
161  
162 1 1;
163  
164 # eof
« Quiq/Confluence/Page.pm ↑ Summary Quiq/TempFile.pm »