line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
2486
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
79
|
|
2
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
104
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Mojo::DOM::Role::Style; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Adds a style method to Mojo::DOM |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
15
|
use Mojo::Base -role; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
15
|
|
9
|
3
|
|
|
3
|
|
2558
|
use Want; |
|
3
|
|
|
|
|
4623
|
|
|
3
|
|
|
|
|
168
|
|
10
|
3
|
|
|
3
|
|
20
|
use List::Util qw/uniq/; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
168
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
16
|
use Mojo::Util qw/dumper/; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1982
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub style { |
15
|
14
|
|
|
14
|
1
|
4368
|
my $self = shift; |
16
|
|
|
|
|
|
|
|
17
|
14
|
|
|
|
|
33
|
my $css = $self->attr('style'); |
18
|
|
|
|
|
|
|
|
19
|
14
|
|
|
|
|
226
|
my ($h, $k) = _from_css($css); |
20
|
|
|
|
|
|
|
|
21
|
14
|
100
|
100
|
|
|
98
|
if (scalar @_ == 1 && ! ref $_[0] && defined $_[0]) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
22
|
1
|
|
|
|
|
32
|
return $h->{shift()} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
elsif (scalar @_ == 1 && ! defined $_[0]) { |
25
|
1
|
|
|
|
|
3
|
delete $self->attr->{'style'}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
elsif ((scalar @_ % 2) == 0 && (scalar @_)) { |
28
|
1
|
|
|
|
|
3
|
my $m = { @_ }; |
29
|
1
|
|
|
|
|
3
|
$css = _to_css($m, []); |
30
|
1
|
|
|
|
|
3
|
$self->attr('style', $css); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif (ref $_[0] eq 'HASH') { |
33
|
2
|
|
|
|
|
3
|
for (keys %{$_[0]}) { $h->{$_} = $_[0]->{$_} } |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
4
|
|
34
|
2
|
|
|
|
|
4
|
$css = _to_css($h, $k); |
35
|
2
|
|
|
|
|
5
|
$self->attr('style', $css); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
13
|
100
|
|
|
|
97
|
if (want('OBJECT')) { |
|
|
100
|
|
|
|
|
|
40
|
5
|
|
|
|
|
271
|
return $self; |
41
|
|
|
|
|
|
|
} elsif (want('HASH')) { |
42
|
3
|
|
|
|
|
237
|
return $h; |
43
|
|
|
|
|
|
|
} else { |
44
|
5
|
|
|
|
|
405
|
return $css; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# my $query = $url->query; |
51
|
|
|
|
|
|
|
# $url = $url->query({merge => 'to'}); |
52
|
|
|
|
|
|
|
# $url = $url->query([append => 'with']); |
53
|
|
|
|
|
|
|
# $url = $url->query(replace => 'with'); |
54
|
|
|
|
|
|
|
# $url = $url->query('a=1&b=2'); |
55
|
|
|
|
|
|
|
# $url = $url->query(Mojo::Parameters->new); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _to_css { |
58
|
3
|
|
|
3
|
|
4
|
my $h = shift; |
59
|
3
|
|
50
|
|
|
7
|
my $k = shift || []; |
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
|
|
24
|
$k = [ uniq (@$k, keys %$h) ]; |
62
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
6
|
my $css = join ';', map { join ':', $_, $h->{$_} } @$k; |
|
7
|
|
|
|
|
22
|
|
64
|
3
|
|
|
|
|
7
|
return $css |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _from_css { |
68
|
14
|
|
|
14
|
|
18
|
my $css = shift; |
69
|
14
|
50
|
|
|
|
29
|
unless ($css) { return wantarray ? ({}, []) : {} } |
|
1
|
100
|
|
|
|
4
|
|
70
|
|
|
|
|
|
|
|
71
|
13
|
|
|
|
|
62
|
my $k = [ map { /^(.+?)\s*:/; $1 } split /\s*;\s*/, $css ]; |
|
35
|
|
|
|
|
94
|
|
|
35
|
|
|
|
|
83
|
|
72
|
13
|
|
|
|
|
44
|
my $h = { map { split /\s*:\s*/, $_, 2 } split /\s*;\s*/, $css }; |
|
35
|
|
|
|
|
102
|
|
73
|
|
|
|
|
|
|
|
74
|
13
|
50
|
|
|
|
47
|
return wantarray ? ($h, $k) : $h |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |