line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TemplateM::Util; # $Id: Util.pm 2 2013-04-02 10:51:49Z abalama $
|
2
|
6
|
|
|
6
|
|
27
|
use strict;
|
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
230
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
TemplateM::Util - Internal utilities used by TemplateM module
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Version 2.21
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use TemplateM::Util;
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
no public subroutines
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 AUTHOR INFORMATION
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Copyright 1995-1998, Lincoln D. Stein. All rights reserved.
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
25
|
|
|
|
|
|
|
it under the same terms as Perl itself.
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SEE ALSO
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
L
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut
|
32
|
|
|
|
|
|
|
|
33
|
6
|
|
|
6
|
|
30
|
use base qw/Exporter/;
|
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
723
|
|
34
|
6
|
|
|
6
|
|
30
|
use vars qw($VERSION);
|
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
3191
|
|
35
|
|
|
|
|
|
|
our $VERSION = 2.21;
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our @EXPORT = qw/read_attributes/;
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub read_attributes {
|
40
|
6
|
|
|
6
|
0
|
18
|
my($order,@param) = @_;
|
41
|
6
|
50
|
|
|
|
22
|
return () unless @param;
|
42
|
|
|
|
|
|
|
|
43
|
6
|
50
|
|
|
|
29
|
if (ref($param[0]) eq 'HASH') {
|
44
|
0
|
|
|
|
|
0
|
@param = %{$param[0]};
|
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
} else {
|
46
|
6
|
100
|
66
|
|
|
68
|
return @param unless (defined($param[0]) && substr($param[0],0,1) eq '-');
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# map parameters into positional indices
|
50
|
3
|
|
|
|
|
5
|
my ($i,%pos);
|
51
|
3
|
|
|
|
|
4
|
$i = 0;
|
52
|
3
|
|
|
|
|
7
|
foreach (@$order) {
|
53
|
42
|
50
|
|
|
|
98
|
foreach (ref($_) eq 'ARRAY' ? @$_ : $_) {
|
54
|
132
|
|
|
|
|
268
|
$pos{lc($_)} = $i;
|
55
|
|
|
|
|
|
|
}
|
56
|
42
|
|
|
|
|
61
|
$i++;
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
6
|
my (@result,%leftover);
|
60
|
3
|
|
|
|
|
21
|
$#result = $#$order; # preextend
|
61
|
3
|
|
|
|
|
11
|
while (@param) {
|
62
|
3
|
|
|
|
|
8
|
my $key = lc(shift(@param));
|
63
|
3
|
|
|
|
|
15
|
$key =~ s/^\-//;
|
64
|
3
|
50
|
|
|
|
10
|
if (exists $pos{$key}) {
|
65
|
3
|
|
|
|
|
12
|
$result[$pos{$key}] = shift(@param);
|
66
|
|
|
|
|
|
|
} else {
|
67
|
0
|
|
|
|
|
0
|
$leftover{$key} = shift(@param);
|
68
|
|
|
|
|
|
|
}
|
69
|
|
|
|
|
|
|
}
|
70
|
|
|
|
|
|
|
|
71
|
3
|
50
|
|
|
|
11
|
push (@result,_make_attributes(\%leftover,1)) if %leftover;
|
72
|
3
|
|
|
|
|
36
|
@result;
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _make_attributes {
|
76
|
0
|
|
|
0
|
|
|
my $attr = shift;
|
77
|
0
|
0
|
0
|
|
|
|
return () unless $attr && ref($attr) && ref($attr) eq 'HASH';
|
|
|
|
0
|
|
|
|
|
78
|
0
|
|
0
|
|
|
|
my $escape = shift || 0;
|
79
|
0
|
|
|
|
|
|
my(@att);
|
80
|
0
|
|
|
|
|
|
foreach (keys %{$attr}) {
|
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my($key) = $_;
|
82
|
0
|
|
|
|
|
|
$key=~s/^\-//;
|
83
|
0
|
|
|
|
|
|
($key="\L$key") =~ tr/_/-/; # parameters are lower case, use dashes
|
84
|
0
|
0
|
|
|
|
|
my $value = $escape ? $attr->{$_} : $attr->{$_};
|
85
|
0
|
0
|
|
|
|
|
push(@att,defined($attr->{$_}) ? qq/$key="$value"/ : qq/$key/);
|
86
|
|
|
|
|
|
|
}
|
87
|
0
|
|
|
|
|
|
return @att;
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1;
|