CSS-DOM

 view release on metacpan or  search on metacpan

lib/CSS/DOM.pm  view on Meta::CPAN

$VERSION = '0.17';

use   # to keep CPANTS happy :-)
   strict;
use   # same here
   warnings;

use CSS::DOM::Exception
	'SYNTAX_ERR' ,'HIERARCHY_REQUEST_ERR', 'INDEX_SIZE_ERR';
use CSS::DOM::Constants 'STYLE_RULE';
use Scalar::Util 'weaken';

require CSS::DOM::RuleList;

use constant 1.03 our $_constants = {
	ruls => 0,
	ownr => 1, # owner rule
	node => 2, # owner node
	dsbl => 3,
	hrfe => 4,
	medi => 5,

lib/CSS/DOM.pm  view on Meta::CPAN


# StyleSheet interface:

sub type { 'text/css' }
sub disabled {
	my $old = (my $self = shift) ->[dsbl];
	@_ and $self->[dsbl] = shift;
	$old
};
sub ownerNode { defined $_[0][node]?$_[0][node]:() }
sub set_ownerNode { weaken($_[0]->[node] = $_[1]) }
sub parentStyleSheet { shift->[prsh]||() }
sub _set_parentStyleSheet { weaken($_[0]->[prsh] = $_[1]) }
sub href { shift->[hrfe] }
sub set_href { $_[0]->[hrfe] = $_[1] }
sub title { no warnings 'uninitialized';
           ''.(shift->ownerNode || return)->attr('title') }

# If you find a bug in here, Media.pm’s method probably also needs fixing.
sub media {
	wantarray ? @{$_[0]->[medi]||return} :
		($_[0]->[medi] ||= (
			require CSS::DOM::MediaList,

lib/CSS/DOM.pm  view on Meta::CPAN

		))
}


# CSSStyleSheet interface:

sub ownerRule {
	shift->[ownr] || ()
}
sub _set_ownerRule {
	weaken($_[0]->[ownr] = $_[1]);
}

# If you find a bug in the following three methods, Media.pm’s methods
# probably also need fixing.
sub cssRules { 
	wantarray
		? @{shift->[ruls]||return}
		: (shift->[ruls]||=new CSS::DOM::RuleList);
}

lib/CSS/DOM/Rule.pm  view on Meta::CPAN


$VERSION = '0.17';

use warnings;
use strict;

use Carp 'croak';
use CSS::DOM::Constants;
use CSS::DOM::Exception qw/ SYNTAX_ERR INVALID_MODIFICATION_ERR /;
use Exporter 5.57 'import';
use Scalar::Util 'weaken';

*EXPORT_OK = $CSS::DOM::Constants::EXPORT_TAGS{rule};
our %EXPORT_TAGS = (all => \our @EXPORT_OK);

use constant 1.03 our $_const = {
# Don’t let these conflict with subclasses!
	prnt => 0,
	shet => 1,
	typs => 2, # token types   These two are not used by subclassed,
	tokn => 3, # tokens        so there’s no chance of a conflict.
};
{ no strict; delete @{__PACKAGE__.'::'}{_const => keys %{our $_const}} }

sub new {
	my $self = bless[],shift;
	my $parent = shift || return $self;
	if($parent->isa('CSS::DOM::Rule')) {
		weaken($$self[shet] = $parent->parentStyleSheet);
		weaken($$self[prnt] = $parent);
	}
	else {
		weaken($$self[shet] = $parent)
	}
	$self;
}

sub type { UNKNOWN_RULE }

# This is used by cssText, both this class’s and subclasses’:
sub _parse { # This method parses the code passed to it and checks to see
             # whether the retval is the same class as  $self,  throwing
             # errors as appropriate.  It returns the new rule resulting

lib/CSS/DOM/Rule.pm  view on Meta::CPAN

		my $new_rule  =  $self->_parse(shift);
		@$self[typs,tokn] = @$new_rule[typs,tokn];
	}
	$old;
};


sub parentStyleSheet { shift->[shet]||() }
sub parentRule       { shift->[prnt]||() }

sub _set_parentStyleSheet { weaken(shift->[shet] = pop) }
sub _set_parentRule       { weaken(shift->[prnt] = pop) }

sub _set_tokens { @{+shift}[typs,tokn] = @_[1,2]; }
  
                              !()__END__()!

=head1 NAME

CSS::DOM::Rule - CSS rule class for CSS::DOM

=head1 VERSION

lib/CSS/DOM/Style.pm  view on Meta::CPAN

package CSS::DOM::Style;

$VERSION = '0.17';

use warnings; no warnings qw' utf8';
use strict;

use CSS::DOM::Exception 'SYNTAX_ERR';
use CSS::DOM::Util qw 'escape_ident unescape';
use Scalar::Util 'weaken';

# ~~~ use overload fallback => 1, '@{}' => 

# Internal object structure
#
# Each style object is a hash ref:
# {
#    owner       => $owner_rule,
#    parser      => $property_parser,
#    mod_handler => sub { ... },  # undef initially

lib/CSS/DOM/Style.pm  view on Meta::CPAN

		my %args = @_;
		$self->{owner} = delete $args{owner};
		$self->{parser}
		 = delete $args{property_parser};
	}
	{
		$self->{parser} ||= (
		    ($self->{owner} || next)->parentStyleSheet || next
		   )->property_parser;
	}
	weaken $self->{owner};
	return $self
}

sub cssText {
	my $self = shift;
	my $out;
	if (defined wantarray) {
		$out = join "; ", map {
			my $pri = $self->getPropertyPriority($_);
			"$_: ".$self->getPropertyValue($_)." !"x!!$pri

lib/CSS/DOM/Value.pm  view on Meta::CPAN


$VERSION = '0.17';

use warnings; no warnings qw 'utf8 parenthesis';;
use strict;

use Carp;
use CSS::DOM::Constants;
use CSS'DOM'Exception 'NO_MODIFICATION_ALLOWED_ERR';
use Exporter 5.57 'import';
use Scalar'Util < weaken reftype >;

use constant 1.03 our $_const = {
    type => 0,
    valu => 1,
    ownr => 2,
    prop => 3,
};
{ no strict; delete @{__PACKAGE__.'::'}{_const => keys %{our $_const}} }

*EXPORT_OK = $CSS::DOM::Constants::EXPORT_TAGS{value};

lib/CSS/DOM/Value.pm  view on Meta::CPAN

	my $self = bless[], shift;
	my %args = @_;
	my $type = $self->[type] = $args{type};
	$type == CSS_CUSTOM
	? !exists $args{value} && croak
	   'new CSS::DOM::Value(type => CSS_CUSTOM) requires a value'
	: $type == CSS_INHERIT
		|| croak "Type must be CSS_CUSTOM or CSS_INHERIT";

	@$self[valu,ownr,prop] = @args{< value owner property >};
	weaken $$self[ownr];

	$self;
}

sub cssValueType { shift->[type] }

sub cssText {
	my $self = shift;
	my $old = $self->[type] == CSS_CUSTOM
		? $self->[valu] : 'inherit'

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';

lib/CSS/DOM/Value/List.pm  view on Meta::CPAN

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;



( run in 0.533 second using v1.01-cache-2.11-cpan-65fba6d93b7 )