line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CSS::Prepare::Property::Background; |
2
|
|
|
|
|
|
|
|
3
|
57
|
|
|
57
|
|
313
|
use Modern::Perl; |
|
57
|
|
|
|
|
100
|
|
|
57
|
|
|
|
|
349
|
|
4
|
|
|
|
|
|
|
|
5
|
57
|
|
|
57
|
|
44013
|
use CSS::Prepare::Property::Expansions; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use CSS::Prepare::Property::Values; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub parse { |
11
|
|
|
|
|
|
|
my $self = shift; |
12
|
|
|
|
|
|
|
my $has_hack = shift; |
13
|
|
|
|
|
|
|
my $location = shift; |
14
|
|
|
|
|
|
|
my %declaration = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $property = $declaration{'property'}; |
17
|
|
|
|
|
|
|
my $value = $declaration{'value'}; |
18
|
|
|
|
|
|
|
my %canonical; |
19
|
|
|
|
|
|
|
my @errors; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $valid_property_or_error = sub { |
22
|
|
|
|
|
|
|
my $type = shift; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $sub = "is_${type}_value"; |
25
|
|
|
|
|
|
|
my $is_valid = 0; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
eval { |
28
|
|
|
|
|
|
|
no strict 'refs'; |
29
|
|
|
|
|
|
|
$is_valid = &$sub( $value ); |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if ( $is_valid ) { |
33
|
|
|
|
|
|
|
$canonical{ $property } = $value; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
|
|
|
|
|
|
push @errors, { |
37
|
|
|
|
|
|
|
error => "invalid ${type} property: '${value}'" |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
&$valid_property_or_error( 'background_colour' ) |
43
|
|
|
|
|
|
|
if 'background-color' eq $property |
44
|
|
|
|
|
|
|
|| 'background-colour' eq $property; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
&$valid_property_or_error( 'background_image' ) |
47
|
|
|
|
|
|
|
if 'background-image' eq $property; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
&$valid_property_or_error( 'background_repeat' ) |
50
|
|
|
|
|
|
|
if 'background-repeat' eq $property; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
&$valid_property_or_error( 'background_attachment' ) |
53
|
|
|
|
|
|
|
if 'background-attachment' eq $property; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
&$valid_property_or_error( 'background_position' ) |
56
|
|
|
|
|
|
|
if 'background-position' eq $property; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if ( 'background' eq $property ) { |
59
|
|
|
|
|
|
|
my %types = ( |
60
|
|
|
|
|
|
|
'background-color' => $background_colour_value, |
61
|
|
|
|
|
|
|
'background-image' => $background_image_value, |
62
|
|
|
|
|
|
|
'background-repeat' => $background_repeat_value, |
63
|
|
|
|
|
|
|
'background-attachment' => $background_attachment_value, |
64
|
|
|
|
|
|
|
'background-position' => $background_position_value, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
%canonical = validate_any_order_shorthand( $value, %types ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
push @errors, { |
70
|
|
|
|
|
|
|
error => "invalid background property: '${value}'" |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
unless %canonical; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if ( defined $canonical{'background-image'} ) { |
76
|
|
|
|
|
|
|
$canonical{'background-image'} = shorten_url_value( |
77
|
|
|
|
|
|
|
$canonical{'background-image'}, |
78
|
|
|
|
|
|
|
$location, |
79
|
|
|
|
|
|
|
$self, |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return \%canonical, \@errors; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub output { |
87
|
|
|
|
|
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
my $block = shift; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my @properties = qw( background-color background-image background-repeat |
91
|
|
|
|
|
|
|
background-attachment background-position ); |
92
|
|
|
|
|
|
|
my @values; |
93
|
|
|
|
|
|
|
my @output; |
94
|
|
|
|
|
|
|
my @value_only; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
foreach my $property ( @properties ) { |
97
|
|
|
|
|
|
|
my $value = $block->{ $property }; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
if ( defined $value ) { |
100
|
|
|
|
|
|
|
$value = shorten_background_position_value( $value ) |
101
|
|
|
|
|
|
|
if 'background-position' eq $property; |
102
|
|
|
|
|
|
|
$value = shorten_colour_value( $value ) |
103
|
|
|
|
|
|
|
if 'background-color' eq $property; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
push @values, |
106
|
|
|
|
|
|
|
sprintf $self->output_format, "${property}:", $value; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
push @value_only, $value |
109
|
|
|
|
|
|
|
if $value; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
if ( 5 == scalar @values ) { |
114
|
|
|
|
|
|
|
my $value = join $self->output_separator, @value_only; |
115
|
|
|
|
|
|
|
push @output, sprintf $self->output_format, 'background:', $value; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
|
|
|
|
|
|
push @output, @values; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
return @output; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub shorten_background_position_value { |
125
|
|
|
|
|
|
|
my $value = shift; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
return |
128
|
|
|
|
|
|
|
unless defined $value; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# CSS2.1 14.2.1: "If only one value is specified, the second value |
131
|
|
|
|
|
|
|
# is assumed to be ’center’." |
132
|
|
|
|
|
|
|
$value =~ s{(.+) \s+ (?: center | 50\% ) $}{$1}x; |
133
|
|
|
|
|
|
|
return $value; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |