line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
## CSS Object Oriented - ~/lib/CSS/Object/Property.pm |
3
|
|
|
|
|
|
|
## Version v0.1.0 |
4
|
|
|
|
|
|
|
## Copyright(c) 2020 DEGUEST Pte. Ltd. |
5
|
|
|
|
|
|
|
## Author: Jacques Deguest <@sitael.local> |
6
|
|
|
|
|
|
|
## Created 2020/06/21 |
7
|
|
|
|
|
|
|
## Modified 2020/06/21 |
8
|
|
|
|
|
|
|
## |
9
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
10
|
|
|
|
|
|
|
package CSS::Object::Property; |
11
|
|
|
|
|
|
|
BEGIN |
12
|
|
|
|
|
|
|
{ |
13
|
6
|
|
|
6
|
|
35
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
164
|
|
14
|
6
|
|
|
6
|
|
53
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
151
|
|
15
|
6
|
|
|
6
|
|
26
|
use parent qw( CSS::Object::Element ); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
24
|
|
16
|
6
|
|
|
6
|
|
305
|
use CSS::Object::Format; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
25
|
|
17
|
6
|
|
|
6
|
|
3369
|
use CSS::Object::Value; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
49
|
|
18
|
6
|
|
|
6
|
|
1241
|
use Devel::Confess; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
22
|
|
19
|
6
|
|
|
6
|
|
3075
|
our $VERSION = 'v0.1.0'; |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub init |
23
|
|
|
|
|
|
|
{ |
24
|
45
|
|
|
45
|
1
|
2367
|
my $self = shift( @_ ); |
25
|
|
|
|
|
|
|
## print( STDERR ref( $self ), "::init() Args received are: ", $self->dump( @_ ), "\n" ); |
26
|
|
|
|
|
|
|
## $self->{format} = ''; |
27
|
45
|
|
|
|
|
142
|
$self->{name} = ''; |
28
|
45
|
|
|
|
|
130
|
$self->{value} = ''; |
29
|
45
|
|
|
|
|
120
|
$self->{values} = []; |
30
|
|
|
|
|
|
|
## $self->{_init_strict_use_sub} = 1; |
31
|
45
|
|
|
|
|
214
|
$self->SUPER::init( @_ ); |
32
|
45
|
|
|
|
|
132
|
$self->format->indent( ' ' ); |
33
|
45
|
|
|
|
|
2197
|
return( $self ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub add_to |
37
|
|
|
|
|
|
|
{ |
38
|
7
|
|
|
7
|
1
|
17
|
my $self = shift( @_ ); |
39
|
7
|
|
50
|
|
|
24
|
my $rule = shift( @_ ) || return( $self->error( "No rule object was provided to add our property to it." ) ); |
40
|
7
|
50
|
|
|
|
229
|
return( $self->error( "Rule object provided (", overload::StrVal( $rule ), ") is not actually a CSS::Object::Rule object." ) ) if( !$self->_is_a( $rule, 'CSS::Object::Rule' ) ); |
41
|
7
|
|
|
|
|
106
|
$self->format->indent( $rule->format->indent ); |
42
|
7
|
|
|
|
|
316
|
$rule->add_property( $self ); |
43
|
7
|
|
|
|
|
17
|
return( $self ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
202
|
|
|
202
|
1
|
7651
|
sub as_string { return( $_[0]->format->property_as_string( $_[0] ) ); } |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub format |
49
|
|
|
|
|
|
|
{ |
50
|
814
|
|
|
814
|
1
|
3010
|
my $self = shift( @_ ); |
51
|
814
|
100
|
|
|
|
1755
|
if( @_ ) |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
# my( $p, $f, $l ) = caller; |
54
|
|
|
|
|
|
|
# $self->message( 3, "Property format called in package $p at line $l in file $f" ); |
55
|
16
|
|
50
|
|
|
53
|
my $format = $self->SUPER::format( @_ ) || return; |
56
|
|
|
|
|
|
|
$self->values->foreach(sub |
57
|
|
|
|
|
|
|
{ |
58
|
15
|
50
|
|
15
|
|
416
|
shift->format( $format ) || return; |
59
|
16
|
|
|
|
|
42
|
}); |
60
|
16
|
|
|
|
|
149
|
$format->indent( ' ' ); |
61
|
16
|
|
|
|
|
822
|
return( $format ); |
62
|
|
|
|
|
|
|
} |
63
|
798
|
|
|
|
|
1800
|
return( $self->_set_get_object( 'format', 'CSS::Object::Format' ) ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
250
|
|
|
250
|
1
|
3716
|
sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); } |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub value |
69
|
|
|
|
|
|
|
{ |
70
|
48
|
|
|
48
|
1
|
4598
|
my $self = shift( @_ ); |
71
|
48
|
100
|
|
|
|
143
|
if( @_ ) |
72
|
|
|
|
|
|
|
{ |
73
|
44
|
|
|
|
|
93
|
my $val = shift( @_ ); |
74
|
44
|
|
|
|
|
79
|
my $valObj; |
75
|
44
|
50
|
|
|
|
163
|
if( $self->_is_a( $val, 'CSS::Object::Value' ) ) |
|
|
50
|
|
|
|
|
|
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
|
|
0
|
$valObj = $val; |
78
|
0
|
|
|
|
|
0
|
$valObj->format( $self->format ); |
79
|
0
|
|
|
|
|
0
|
$valObj->debug( $self->debug ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
## Array of values, which could be |
82
|
|
|
|
|
|
|
elsif( $self->_is_array( $val ) ) |
83
|
|
|
|
|
|
|
{ |
84
|
|
|
|
|
|
|
## Make sure this is a Module::Generic::Array |
85
|
0
|
|
|
|
|
0
|
$val = $self->new_array( $val ); |
86
|
|
|
|
|
|
|
$val->foreach(sub |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
0
|
0
|
0
|
|
0
|
if( $self->_is_a( $_, 'CSS::Object::Value' ) ) |
|
|
0
|
|
|
|
|
|
89
|
|
|
|
|
|
|
{ |
90
|
0
|
|
|
|
|
0
|
$self->values->push( $_ ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif( !ref( $_ ) || $self->_is_a( $_, 'Module::Generic::Scalar' ) ) |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
|
|
0
|
$valObj = CSS::Object::Value->new( "$_", |
95
|
|
|
|
|
|
|
debug => $self->debug, |
96
|
|
|
|
|
|
|
format => $self->format, |
97
|
|
|
|
|
|
|
); |
98
|
0
|
|
|
|
|
0
|
$self->values->push( $_ ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else |
101
|
|
|
|
|
|
|
{ |
102
|
0
|
|
|
|
|
0
|
CORE::warn( "Got value \"$_\" in an array of values provided for this property, but I just do not know what to do with it.\n" ); |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
0
|
}); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else |
107
|
|
|
|
|
|
|
{ |
108
|
|
|
|
|
|
|
# $self->message( 3, "Creating a value object for value '$val'." ); |
109
|
44
|
|
|
|
|
738
|
$valObj = CSS::Object::Value->new( $val, |
110
|
|
|
|
|
|
|
debug => $self->debug, |
111
|
|
|
|
|
|
|
format => $self->format, |
112
|
|
|
|
|
|
|
); |
113
|
44
|
50
|
|
|
|
145
|
defined( $valObj ) || return( $self->error( "Unable to initialise CSS::Object::Value object for value \"$val\"." ) ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
# $self->message( 3, "Adding new value object '", overload::StrVal( $valObj ), " ($val) to our stack." ); |
116
|
44
|
|
|
|
|
153
|
$self->values->set( $valObj ); |
117
|
|
|
|
|
|
|
# $self->message( 3, "Stack of values contains ", $self->values->length, " elements. Returning the CSS::Object::Value object (", $valObj->as_string, ")." ); |
118
|
44
|
|
|
|
|
1803
|
return( $valObj ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
# my $last = $self->values->last; |
121
|
|
|
|
|
|
|
# $self->message( 3, "Returning value object '", $last, "'." ); |
122
|
4
|
|
|
|
|
19
|
return( $self->values->last ); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
## Array of CSS::Object::Value objects |
126
|
266
|
|
|
266
|
1
|
7699
|
sub values { return( shift->_set_get_array_as_object( 'values', @_ ) ); } |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
0
|
1
|
|
sub values_as_string { return( $_[0]->format->values_as_string( $_[0]->values ) ); } |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=encoding utf-8 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 NAME |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
CSS::Object::Property - CSS Object Oriented Property |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SYNOPSIS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
use CSS::Object::Property; |
143
|
|
|
|
|
|
|
my $prop = CSS::Object::Property->new( |
144
|
|
|
|
|
|
|
name => 'display', |
145
|
|
|
|
|
|
|
value => 'inline-block', |
146
|
|
|
|
|
|
|
format => $format_object, |
147
|
|
|
|
|
|
|
debug => 3, |
148
|
|
|
|
|
|
|
) || die( CSS::Object::Property->error ); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 VERSION |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
v0.1.0 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 DESCRIPTION |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L<CSS::Object::Property> is a class to represent a CSS property. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 new |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
To instantiate a new L<CSS::Object::Property> object, pass an hash reference of following parameters: |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=over 4 |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item I<debug> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This is an integer. The bigger it is and the more verbose is the output. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item I<format> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This is a L<CSS::Object::Format> object or one of its child modules. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item I<name> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This is the property's name. When provided, this calls the method L</name> to store the value. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item I<value> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This is the property's name. When provided, this calls the method L</value> to store the value. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=back |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 METHODS |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 format |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This is a L<CSS::Object::Format> object or one of its child modules. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 as_string |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
This calls the L</format> and its method L<CSS::Object::Format/property_as_string> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
It returns the css string produced or undef and sets an L<Module::Generic::Exception> upon error. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 format |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This sets or gets the L<CSS::Object::Format> object. When set, this will share the formatter with all its L<CSS::Object::Value> objects. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 name |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Sets or gets the property's name. The name stored here becomes a L<Module::Generic::Scalar> and thus all its object methods can be used |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 value |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Sets the value or get the last value for this property. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
It takes either a string or a L<CSS::Object::Value> object and add it to the list of stored values for this property using the L</properties> method. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
It returns the last property value object in the L</values> array. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 values |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
This sets or gets the list of L<CSS::Object::Value> objects. It uses a L<Module::Generic::Array> object to store those value objects. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
It returns the array object. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head2 values_as_string |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This returns a string representation of all the L<CSS::Object::Value> objects currently stored. It does this by calling the format's method L<CSS::Object::Format/values_as_string> |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head1 AUTHOR |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 SEE ALSO |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
L<CSS::Object> |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Copyright (c) 2020 DEGUEST Pte. Ltd. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
You can use, copy, modify and redistribute this package and associated |
235
|
|
|
|
|
|
|
files under the same terms as Perl itself. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |