CSS-DOM
view release on metacpan or search on metacpan
lib/CSS/DOM/Style.pm view on Meta::CPAN
# Parse out the priority first
my $priority;
if($types =~ /(s?(ds?))i\z/ and $tokens->[$-[2]] eq '!') {
$types =~ s///;
$priority = unescape pop @$tokens;
pop @$tokens for 1..length $1;
} else {
$priority = '';
}
# Get the prop & priority hashes
my $props = $$self{props} ||= {};
my $pri = $$self{pri} ||={};
# See if we need to parse the value
my $val;
if(my $spec = $self->{parser}) {
my(@args) = $spec->match($name,$types,$tokens)
or return;
if(@args == 1) {
while(my($k,$v) = each %{ $args[0] }) {
$self->removeProperty($k), next
if $v eq "";
exists $$props{$k=lc$k}
or push @{$$self{names}}, $k;
$$props{$k} = $v;
$$pri{$k} = $priority;
}
return;
}
else {
$val = \@args;
}
}
else { $val = join "", @$tokens }
# Assign the value & priority
exists $$props{$name=lc$name} or push @{$$self{names}}, $name;
$$props{$name} = $val;
$$pri{$name} = $priority;
}
{ my $prop_re = qr/[a-z]+(?:[A-Z][a-z]+)*/;
sub can {
SUPER::can { shift } @_ or
$_[0] =~ /^$prop_re\z/o ? \&{+shift} : undef;
}
sub AUTOLOAD {
my $self = shift;
if(our $AUTOLOAD =~ /(?<=:)($prop_re)\z/o) {
(my $prop = $1) =~ s/([A-Z])/-\l$1/g;
my $val;
defined wantarray
and $val = $self->getPropertyValue($prop);
@_ and $self->setProperty($prop, shift);
return $val;
} else {
die "Undefined subroutine $AUTOLOAD called at ",
join(" line ", (caller)[1,2]), ".\n";
}
}
sub DESTROY{}
}
*cssFloat = \&float;
sub modification_handler {
my $old = (my $self = shift)->{mod_handler};
$self->{mod_handler} = shift if @_;
$old;
}
sub _m#odified
{
&{$_[0]->{mod_handler} or return}($_[0]);
}
sub property_parser { shift->{parser} }
sub length { # We put this one last to avoid having to say CORE::length
# elsewhere.
scalar @{shift->{names}||return 0}
}
!()__END__()!
=head1 NAME
CSS::DOM::Style - CSS style declaration class for CSS::DOM
=head1 VERSION
Version 0.17
=head1 SYNOPSIS
use CSS::DOM::Style;
$style = CSS::DOM::Style::parse(' text-decoration: none ');
$style->cssText; # returns 'text-decoration: none'
$style->cssText('color: blue'); # replace contents
$style->getPropertyValue('color'); # 'blue'
$style->color; # same
$style->setProperty(color=>'green'); # change it
$style->color('green'); # same
=head1 DESCRIPTION
This module provides the CSS style declaration class for L<CSS::DOM>. (A
style declaration is what comes between the braces in C<p { margin: 0 }>.)
It
implements
the CSSStyleDeclaration DOM interface.
=head1 CONSTRUCTORS
( run in 0.676 second using v1.01-cache-2.11-cpan-5735350b133 )