File Coverage

lib/HTML/Object/DOM/Element/Style.pm
Criterion Covered Total %
statement 28 31 90.3
branch 2 4 50.0
condition n/a
subroutine 9 12 75.0
pod 4 4 100.0
total 43 51 84.3


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## HTML Object - ~/lib/HTML/Object/DOM/Element/Style.pm
3             ## Version v0.2.0
4             ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2021/12/23
7             ## Modified 2022/09/18
8             ## All rights reserved
9             ##
10             ##
11             ## This program is free software; you can redistribute it and/or modify it
12             ## under the same terms as Perl itself.
13             ##----------------------------------------------------------------------------
14             package HTML::Object::DOM::Element::Style;
15             BEGIN
16             {
17 2     2   2236 use strict;
  2         10  
  2         101  
18 2     2   25 use warnings;
  2         9  
  2         124  
19 2     2   23 use parent qw( HTML::Object::DOM::Element );
  2         18  
  2         32  
20 2     2   249 use vars qw( $VERSION );
  2         16  
  2         147  
21 2     2   25 use HTML::Object::DOM::Element::Shared qw( :style );
  2         14  
  2         532  
22 2     2   67 our $VERSION = 'v0.2.0';
23             };
24              
25 2     2   21 use strict;
  2         15  
  2         69  
26 2     2   20 use warnings;
  2         11  
  2         502  
27              
28             sub init
29             {
30 1     1 1 120 my $self = shift( @_ );
31 1         164 $self->{scoped} = undef;
32 1         8 $self->{_init_strict_use_sub} = 1;
33 1 50       24 $self->SUPER::init( @_ ) || return( $self->pass_error );
34 1 50       6 $self->{tag} = 'style' if( !CORE::length( "$self->{tag}" ) );
35 1         16 return( $self );
36             }
37              
38             # Note: property disabled inherited
39              
40             # Note: property media
41 0     0 1   sub media : lvalue { return( shift->_set_get_property( 'media', @_ ) ); }
42              
43             # Note: property scoped
44 0     0 1   sub scoped : lvalue { return( shift->_set_get_boolean( 'scoped', @_ ) ); }
45              
46             # Note: property sheet read-only
47 0     0 1   sub sheet { return; }
48              
49             # Note: property type inherited
50              
51             1;
52             # NOTE: POD
53             __END__
54              
55             =encoding utf-8
56              
57             =head1 NAME
58              
59             HTML::Object::DOM::Element::Style - HTML Object DOM Style Class
60              
61             =head1 SYNOPSIS
62              
63             use HTML::Object::DOM::Element::Style;
64             my $style = HTML::Object::DOM::Element::Style->new ||
65             die( HTML::Object::DOM::Element::Style->error, "\n" );
66              
67             =head1 VERSION
68              
69             v0.2.0
70              
71             =head1 DESCRIPTION
72              
73             This interface represents a C<style> element. It inherits properties and methods from its parent, L<HTML::Object::DOM::Element>.
74              
75             =head1 INHERITANCE
76              
77             +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
78             | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Style |
79             +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
80              
81             =head1 PROPERTIES
82              
83             Inherits properties from its parent L<HTML::Object::DOM::Element>
84              
85             =head2 disabled
86              
87             Is a boolean value reflecting the HTML attribute representing whether or not the stylesheet is disabled (true) or not (false).
88              
89             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/disabled>
90              
91             =head2 media
92              
93             Is a string representing the intended destination medium for style information.
94              
95             Example:
96              
97             <!doctype html>
98             <html>
99             <head>
100             <link id="LinkedStyle" rel="stylesheet" href="document.css" type="text/css" media="screen" />
101             <style id="InlineStyle" rel="stylesheet" type="text/css" media="screen, print">
102             p { color: blue; }
103             </style>
104             </head>
105             <body>
106             </body>
107             </html>
108              
109             say( 'LinkedStyle: ' . $doc->getElementById( 'LinkedStyle' )->media ); # 'screen'
110             say( 'InlineStyle: ' . $doc->getElementById( 'InlineStyle' )->media ); # 'screen, print'
111              
112             Operators that can be used in the C<media> value:
113              
114             =over 4
115              
116             =item * and
117              
118             Specifies an AND operator
119              
120             =item * , (comma)
121              
122             Specifies an OR operator
123              
124             =item * not
125              
126             Specifies a NOT operator
127              
128             =back
129              
130             Device names (not enforced by this interface) that can be used in the C<media> value:
131              
132             =over 4
133              
134             =item * all
135              
136             Suitable for all devices. This is the default.
137              
138             =item * aural
139              
140             Speech synthesizers
141              
142             =item * braille
143              
144             Braille feedback devices -- for the visually impaired
145              
146             =item * handheld
147              
148             Handheld devices with small screens and limited bandwidth
149              
150             =item * projection
151              
152             Projector devices
153              
154             =item * print
155              
156             Printed pages or in print-preview mode
157              
158             =item * screen
159              
160             Computer screens
161              
162             =item * tty
163              
164             Teletypes and similar devices using a fixed-pitch character grid
165              
166             =item * tv
167              
168             Television type devices with low resolution and limited scrolling
169              
170             =back
171              
172             Tokens that can be used in the C<media> value:
173              
174             =over 4
175              
176             =item * aspect-ratio (width/height)
177              
178             Ratio of width/height of the targeted display. Name can be prefixed with min- or max-.
179              
180             =item * color (integer)
181              
182             Bits per color of targeted display. Name can be prefixed with min- or max-.
183              
184             =item * color-index (integer)
185              
186             Number of colors the targeted display supports. Name can be prefixed with min- or max-.
187              
188             =item * device-aspect-ratio (width/height)
189              
190             Ratio of width/height of the device or paper. Name can be prefixed with min- or max-.
191              
192             =item * device-height (pixels)
193              
194             Height of the device or paper. Name can be prefixed with min- or max-.
195              
196             =item * device-width (pixels)
197              
198             Width of the device or paper. Name can be prefixed with min- or max-.
199              
200             =item * grid (1 = grid, 0 = otherwise)
201              
202             Whether output device is a grid or bitmap type.
203              
204             =item * height (pixels)
205              
206             Height of targeted display. Name can be prefixed with min- or max-.
207              
208             =item * monochrome (integer)
209              
210             Bits per pixel in a monochrome frame buffer. Name can be prefixed with min- or max-.
211              
212             =item * orientation (landscape, portrait)
213              
214             Orientation of the device or paper.
215              
216             =item * resolution (dpi or dpcm)
217              
218             Pixel density of the targeted display or paper. Name can be prefixed with min- or max-.
219              
220             =item * scan (progressive interlace)
221              
222             Scanning method of a tv display.
223              
224             =item * width (pixels)
225              
226             Width of targeted display. Name can be prefixed with min- or max-.
227              
228             =back
229              
230             Example:
231              
232             <style media="all and (orientation: portrait)"></style>
233             <style media="screen and (aspect-ratio: 16/10)"></style>
234             <style media="screen , (device-height: 540px)"></style>
235             <style media="screen , (aspect-ratio: 5/4)"></style>
236             <style media="screen and not (min-color-index: 512)"></style>
237             <style media="screen and (min-width: 1200px)"></style>
238             <style media="screen and (max-height: 720px)"></style>
239             <style media="handheld and (grid: 1)"></style>
240             <style media="tv and (scan: interlace)"></style>
241             <style media="print and (resolution: 400dpi)"></style>
242             <style media="screen and (max-monochrome: 2)"></style>
243             <style media="screen and not (device-width: 360px)"></style>
244             <style media="screen , (color: 8)"></style>
245              
246             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/media>
247              
248             =head2 scoped
249              
250             Is a boolean value indicating if the element applies to the whole document (false) or only to the parent's sub-tree (true).
251              
252             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/scoped>
253              
254             =head2 sheet
255              
256             Under perl, this always returns C<undef>, because processing a stylesheet would be time consuming, and an object is returned only when there is a C<href> HTML attribute set.
257              
258             Under JavaScript, this returns the C<CSSStyleSheet> object associated with the given element, or C<undef> if there is none
259              
260             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/sheet>
261              
262             =head2 type
263              
264             Is a string representing the type of style being applied by this statement.
265              
266             Example:
267              
268             if( $newStyle->type != "text/css" )
269             {
270             # not supported!
271             warnCSS();
272             }
273              
274             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/type>
275              
276             =head1 METHODS
277              
278             Inherits methods from its parent L<HTML::Object::DOM::Element>
279              
280             =head1 AUTHOR
281              
282             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
283              
284             =head1 SEE ALSO
285              
286             L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement>, L<Mozilla documentation on style element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style>
287              
288             =head1 COPYRIGHT & LICENSE
289              
290             Copyright(c) 2021 DEGUEST Pte. Ltd.
291              
292             All rights reserved
293              
294             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
295              
296             =cut