File Coverage

lib/HTML/Object/DOM/Element/TableCell.pm
Criterion Covered Total %
statement 35 60 58.3
branch 2 8 25.0
condition 2 7 28.5
subroutine 12 29 41.3
pod 20 20 100.0
total 71 124 57.2


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## HTML Object - ~/lib/HTML/Object/DOM/Element/TableCell.pm
3             ## Version v0.2.0
4             ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2022/01/07
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::TableCell;
15             BEGIN
16             {
17 2     2   1847 use strict;
  2         5  
  2         67  
18 2     2   18 use warnings;
  2         4  
  2         67  
19 2     2   12 use parent qw( HTML::Object::DOM::Element );
  2         4  
  2         12  
20 2     2   173 use vars qw( $VERSION );
  2         8  
  2         124  
21 2     2   13 use HTML::Object::DOM::Element::Shared qw( :tablecell );
  2         4  
  2         311  
22 2     2   41 our $VERSION = 'v0.2.0';
23             };
24              
25 2     2   11 use strict;
  2         4  
  2         60  
26 2     2   10 use warnings;
  2         5  
  2         1592  
27              
28             sub init
29             {
30 12     12 1 1040 my $self = shift( @_ );
31             # Could be also <th>
32 12 50 33     241 $self->{tag} = 'td' if( !defined( $self->{tag} ) || !CORE::length( "$self->{tag}" ) );
33 12         37 $self->{_init_strict_use_sub} = 1;
34 12 50       75 $self->SUPER::init( @_ ) || return( $self->pass_error );
35             $self->_set_get_internal_attribute_callback( headers => sub
36             {
37 0     0   0 my( $this, $val ) = @_;
38 0         0 my $list;
39 0 0       0 return if( !( $list = $this->{_headers_list} ) );
40             # $list->debug( $self->debug );
41 0         0 $list->update( $val );
42 12         169 });
43 12         49 return( $self );
44             }
45              
46             # Note: property abbr
47 0     0 1 0 sub abbr : lvalue { return( shift->_set_get_property( 'abbr', @_ ) ); }
48              
49             # Note: deprecated property align is inherited
50              
51             # Note: deprecated property axis
52 0     0 1 0 sub axis : lvalue { return( shift->_set_get_property( 'axis', @_ ) ); }
53              
54             # Note: deprecated property bgColor
55 0     0 1 0 sub bgColor : lvalue { return( shift->_set_get_property( 'bgcolor', @_ ) ); }
56              
57 0     0 1 0 sub bgcolor : lvalue { return( shift->bgColor( @_ ) ); }
58              
59             # Note: property cellIndex read-only
60             sub cellIndex
61             {
62 1     1 1 82505 my $self = shift( @_ );
63 1   50     11 my $parent = $self->parent || return;
64 1         38 my $siblings = $parent->children;
65 1         107 my $pos = $siblings->pos( $self );
66 1         73 return( $pos );
67             }
68              
69             # Note: deprecated property ch
70 0     0 1 0 sub ch : lvalue { return( shift->_set_get_property( 'ch', @_ ) ); }
71              
72             # Note: deprecated property chOff
73 0     0 1 0 sub chOff : lvalue { return( shift->_set_get_property( 'choff', @_ ) ); }
74              
75 0     0 1 0 sub choff : lvalue { return( shift->chOff( @_ ) ); }
76              
77             # Note: property colSpan
78 0     0 1 0 sub colSpan : lvalue { return( shift->_set_get_property( 'colspan', @_ ) ); }
79              
80 0     0 1 0 sub colspan : lvalue { return( shift->colSpan( @_ ) ); }
81              
82             # Note: property colgroup
83 0     0 1 0 sub colgroup : lvalue { return( shift->_set_get_property( 'colgroup', @_ ) ); }
84              
85             # Note: property headers read-only
86             sub headers
87             {
88 0     0 1 0 my $self = shift( @_ );
89 0 0       0 unless( $self->{_headers_list} )
90             {
91 0         0 my $headers = $self->attr( 'headers' );
92 0         0 require HTML::Object::TokenList;
93 0   0     0 $self->{_headers_list} = HTML::Object::TokenList->new( $headers, element => $self, attribute => 'headers', debug => $self->debug ) ||
94             return( $self->pass_error( HTML::Object::TokenList->error ) );
95             }
96 0         0 return( $self->{_headers_list} );
97             }
98              
99             # Note: deprecated property height is inherited
100              
101             # Note: deprecated property noWrap
102 0     0 1 0 sub noWrap : lvalue { return( shift->_set_get_property( 'nowrap', @_ ) ); }
103              
104 0     0 1 0 sub nowrap : lvalue { return( shift->noWrap( @_ ) ); }
105              
106             # Note: property rowSpan
107 1     1 1 15 sub rowSpan : lvalue { return( shift->_set_get_property( 'rowspan', @_ ) ); }
108              
109 1     1 1 78 sub rowspan : lvalue { return( shift->rowSpan( @_ ) ); }
110              
111             # Note: property scope
112 0     0 1   sub scope : lvalue { return( shift->_set_get_property( 'scope', @_ ) ); }
113              
114             # Note: deprecated property vAlign
115 0     0 1   sub vAlign : lvalue { return( shift->_set_get_property( 'valign', @_ ) ); }
116              
117 0     0 1   sub valign : lvalue { return( shift->vAlign( @_ ) ); }
118              
119             # Note: deprecated property width is inherited
120              
121             1;
122             # NOTE: POD
123             __END__
124              
125             =encoding utf-8
126              
127             =head1 NAME
128              
129             HTML::Object::DOM::Element::TableCell - HTML Object DOM TableCell Class
130              
131             =head1 SYNOPSIS
132              
133             use HTML::Object::DOM::Element::TableCell;
134             my $cell = HTML::Object::DOM::Element::TableCell->new( tag => 'th' ) ||
135             die( HTML::Object::DOM::Element::TableCell->error, "\n" );
136              
137             =head1 VERSION
138              
139             v0.2.0
140              
141             =head1 DESCRIPTION
142              
143             This interface provides special properties and methods (beyond the regular L<HTML::Object::DOM::Element> interface it also has available to it by inheritance) for manipulating the layout and presentation of table cells, either header (C<th>) or data cells (C<td>), in an HTML document.
144              
145             =head1 INHERITANCE
146              
147             +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +---------------------------------------+
148             | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::TableCell |
149             +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +---------------------------------------+
150              
151             =head1 PROPERTIES
152              
153             Inherits properties from its parent L<HTML::Object::DOM::Element>
154              
155             =head2 abbr
156              
157             A string which can be used on C<th> elements (not on C<td>), specifying an alternative label for the header cell. This alternate label can be used in other contexts, such as when describing the headers that apply to a data cell. This is used to offer a shorter term for use by screen readers in particular, and is a valuable accessibility tool. Usually the value of abbr is an abbreviation or acronym, but can be any text that's appropriate contextually.
158              
159             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/abbr>
160              
161             =head2 cellIndex
162              
163             Read-only.
164              
165             A long integer representing the cell's position in the cells collection of the C<tr> the cell is contained within. If the cell does not belong to a C<tr>, it returns C<undef> (C<-1> normally under JavaScript).
166              
167             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/cellIndex>
168              
169             =head2 colSpan
170              
171             An unsigned long integer indicating the number of columns this cell must span; this lets the cell occupy space across multiple columns of the table. It reflects the colspan HTML attribute.
172              
173             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/colSpan>
174              
175             =head2 colspan
176              
177             Alias for L</colSpan>
178              
179             =head2 headers
180              
181             Read-only.
182              
183             A L<TokenList|HTML::Object::TokenList> describing a list of id of C<th> elements that represents headers associated with the cell. It reflects the headers HTML attribute.
184              
185             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/headers>
186              
187             =head2 rowSpan
188              
189             An unsigned long integer indicating the number of rows this cell must span; this lets a cell occupy space across multiple rows of the table. It reflects the rowspan HTML attribute.
190              
191             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/rowSpan>
192              
193             =head2 rowspan
194              
195             Alias for L</rowSpan>
196              
197             =head2 scope
198              
199             A string indicating the scope of a C<th> cell. Header cells can be configured, using the scope property, the apply to a specified row or column, or to the not-yet-scoped cells within the current row group (that is, the same ancestor L<thead|HTML::Object::DOM::Element::TableSection>, L<tbody|HTML::Object::DOM::Element::TableSection>, or L<tfoot|HTML::Object::DOM::Element::TableSection> element). If no value is specified for scope, the header is not associated directly with cells in this way. Permitted values for scope are:
200              
201             Note that, under perl, those values are not enforced.
202              
203             =over 4
204              
205             =item col
206              
207             The header cell applies to the following cells in the same column (or columns, if colspan is used as well), until either the end of the column or another C<th> in the column establishes a new scope.
208              
209             =item colgroup
210              
211             The header cell applies to all cells in the current column group that do not already have a scope applied to them. This value is only allowed if the cell is in a column group.
212              
213             =item row
214              
215             The header cell applies to the following cells in the same row (or rows, if rowspan is used as well), until either the end of the row or another C<th> in the same row establishes a new scope.
216              
217             =item rowgroup
218              
219             The header cell applies to all cells in the current row group that do not already have a scope applied to them. This value is only allowed if the cell is in a row group.
220              
221             =item The empty string ("")
222              
223             The header cell has no predefined scope; the user agent will establish the scope based on contextual clues.
224              
225             =back
226              
227             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/scope>
228              
229             =head1 METHODS
230              
231             Inherits methods from its parent L<HTML::Object::DOM::Element>
232              
233             =head1 DEPRECATED PROPERTIES
234              
235             =head2 align
236              
237             A string containing an enumerated value reflecting the align attribute. It indicates the alignment of the element's contents with respect to the surrounding context. The possible values are C≤left>, C<right>, and C<center>.
238              
239             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/align>
240              
241             =head2 axis
242              
243             A string containing a name grouping cells in virtual. It reflects the obsolete axis attribute.
244              
245             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/axis>
246              
247             =head2 bgColor
248              
249             A string containing the background color of the cells. It reflects the obsolete bgcolor attribute.
250              
251             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/bgColor>
252              
253             =head2 bgcolor
254              
255             Alias for L</bgColor>
256              
257             =head2 ch
258              
259             A string containing one single chararcter. This character is the one to align all the cell of a column on. It reflects the char and default to the decimal points associated with the language, e.g. '.' for English, or ',' for French. This property was optional and was not very well supported.
260              
261             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/ch>
262              
263             =head2 chOff
264              
265             A string containing a integer indicating how many characters must be left at the right (for left-to-right scripts; or at the left for right-to-left scripts) of the character defined by L</ch>. This property was optional and was not very well supported.
266              
267             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/chOff>
268              
269             =head2 choff
270              
271             Alias for L</chOff>
272              
273             =head2 height
274              
275             A string containing a length of pixel of the hinted height of the cell. It reflects the obsolete height HTML attribute.
276              
277             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/height>
278              
279             =head2 noWrap
280              
281             A boolean value reflecting the nowrap HTML attribute and indicating if cell content can be broken in several lines.
282              
283             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/noWrap>
284              
285             =head2 nowrap
286              
287             Alias for L</noWrap>
288              
289             =head2 vAlign
290              
291             A string representing an enumerated value indicating how the content of the cell must be vertically aligned. It reflects the valign HTML attribute and can have one of the following values: C<top>, C<middle>, C<bottom>, or C<baseline>. Use the CSS vertical-align property instead.
292              
293             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/vAlign>
294              
295             =head2 valign
296              
297             Alias for L</vAlign>
298              
299             =head2 width
300              
301             A string specifying the number of pixels wide the cell should be drawn, if possible. This property reflects the also obsolete width HTML attribute. Use the CSS width property instead.
302              
303             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement/width>
304              
305             =head1 AUTHOR
306              
307             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
308              
309             =head1 SEE ALSO
310              
311             L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement>, L<Mozilla documentation on tablecell element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tablecell>
312              
313             =head1 COPYRIGHT & LICENSE
314              
315             Copyright(c) 2022 DEGUEST Pte. Ltd.
316              
317             All rights reserved
318              
319             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
320              
321             =cut