CSS-DOM
view release on metacpan or search on metacpan
lib/CSS/DOM/Value/List.pm view on Meta::CPAN
package CSS::DOM::Value::List;
$VERSION = '0.17';
use CSS'DOM'Constants <CSS_VALUE_LIST NO_MODIFICATION_ALLOWED_ERR>;
use Scalar'Util 'weaken';
# Object of this class are hashes, with the following keys:
# c: CSS code
# v: values
# s: separator
# o: owner
# p: property
sub DOES {
return 1 if $_[1] eq 'CSS::DOM::Value';
goto &UNIVERSAL'DOES if defined &UNIVERSAL'DOES;
}
use overload
fallback => 1,
'@{}' => sub { tie my @shext, __PACKAGE__, shift; \@shext };
sub new {
my $class = shift;
my %args = @_;
my %self;
@self{< c v s o p >}
= @args{< css values separator owner property >};
weaken $self{o};
bless \%self, $class;
}
sub cssText {
my $self = shift;
my $old;
if(defined wantarray) {{
if(!defined $$self{c} || grep ref ne 'ARRAY', @{$$self{v}}) {
@{$$self{v}} or $old = 'none', last;
require CSS'DOM'Value'Primitive;
my @args; my $index = 0;
for(@{$$self{v}}) {
next unless ref eq 'ARRAY';
@args or @args = (
(owner => property => @$self{<o p>})[0,2,1,3], index => $index
);
$_ = new CSS'DOM'Value'Primitive @$_, @args;
}
no warnings 'uninitialized';
$old = join length $$self{s} ? $$self{s} : ' ',
map cssText $_, @{$$self{v}}
}
else { $old = $$self{c} }
}}
if(@_) { # assignment
die new CSS'DOM'Exception
NO_MODIFICATION_ALLOWED_ERR,
"Unowned value objects cannot be modified"
unless my $owner = $self->{o};
die new CSS'DOM'Exception
NO_MODIFICATION_ALLOWED_ERR,
"CSS::DOM::Value objects that do not know to which "
."property they belong cannot be modified"
unless my $prop = $self->{p};
if(
my @arsg
= $owner->property_parser->match($prop, $_[0])
) {
require CSS'DOM'Value;
CSS'DOM'Value::_apply_args_to_self($self,$owner,$prop,@arsg);
}
if(my $mh = $owner->modification_handler) {
&$mh();
}
}
$old;
}
sub cssValueType { CSS_VALUE_LIST }
sub item {
my($self, $index) = @_;
my $v = $self->{v} || return;
exists $$v[$index] or return;
for($$v[$index]) {
defined or return;
ref eq 'ARRAY' or return exit die return $_;
( run in 0.312 second using v1.01-cache-2.11-cpan-e1769b4cff6 )