1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
package CSS::DOM::Rule::Page;
$VERSION = '0.15';
use warnings; no warnings qw 'utf8 parenthesis';
use strict;
use CSS::DOM::Exception qw/ SYNTAX_ERR /;
use CSS::DOM::Rule;
our @ISA = 'CSS::DOM::Rule';
use constant 1.03 our $_const = {
# Don't let this conflict with the superclass.
styl => 2,
selc => 3,
};
{ no strict; delete @{__PACKAGE__.'::'}{_const => keys %{our $_const}} }
# overrides:
sub type { CSS::DOM::Rule::PAGE_RULE }
sub cssText {
my $self = shift;
my $old;
if(defined wantarray) {
$old = "$self->[selc] { "
. $self->[styl]->cssText ." }\n";
}
if (@_) {
require CSS::DOM::Parser;
my $new_rule = $self->_parse(shift);
@$self[styl,selc] = @$new_rule[styl,selc];
}
$old;
};
# CSSPageRule interface:
sub selectorText {
my $old = (my $self = shift)->[selc];
if(@_){
# ~~~ I need to make this use the parser’s tokenise func.
# need tests as well; this shouldn’t accept anything
# that would make it technically an unknown rule.
(my $sel = shift) =~
/^[ \t\r\n\f]*\@page(?![_a-z\200-\377]|\\[^\r\n\f])/
or die CSS::DOM::Exception->new(SYNTAX_ERR,
'@page selectors must begin with "@page"');
$self->[selc] = $sel ;
}
$old;
}
# ~~~ Do we need this?
#sub _set_selector_tokens {
#
#}
sub style {
$_[0]->[styl] ||= do {
require CSS::DOM::Style;
new CSS::DOM::Style shift
};
}
!()__END__()!
=head1 NAME
CSS::DOM::Rule::Page - CSS @page rule class for CSS::DOM
=head1 VERSION
Version 0.15
=head1 SYNOPSIS
use CSS::DOM;
my $page_rule = CSS::DOM->parse(
'@page :first { stuff: other stuff }'
)->cssRules->[0];
$page_rule->selectorText; # '@page :first'
$page_rule->style; # a CSS::DOM::Style object
$page_rule->style->stuff; # 'other stuff'
=head1 DESCRIPTION
This module implements CSS @page rules for L<CSS::DOM>. It inherits
from
L<CSS::DOM::Rule> and implements
the CSSPageRule DOM interface.
=head1 METHODS
=over 4
=item selectorText
Returns a string representing the selector(s). Pass an argument to set it.
=item style
Returns the CSS::DOM::Style object representing the declaration block
of this rule.
=back
=head1 SEE ALSO
L<CSS::DOM>
L<CSS::DOM::Style>
L<CSS::DOM::Rule>
|