DOM/Rule/Page.pm

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