blib/lib/HTML/Object/DOM/Element/Slot.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 56 CC 2 SCAR 9.4
CC
2
Cov
0%
init
6.0
BEGIN
2.0
assign
2.0
CRAP 2.6
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Slot.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/01/06
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::Slot;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( HTML::Object::DOM::Element );
21 use vars qw( $VERSION );
22 use HTML::Object::DOM::Element::Shared qw( :slot );
23 our $VERSION = 'v0.2.0';
24 };
25  
26 use strict;
27 use warnings;
28  
29 sub init
30 {
31 my $self = shift( @_ );
32 $self->{_init_strict_use_sub} = 1;
33 $self->SUPER::init( @_ ) || return( $self->pass_error );
34 $self->{tag} = 'slot' if( !CORE::length( "$self->{tag}" ) );
35 return( $self );
36 }
37  
38 sub assign { return; }
39  
40 sub assignedElements { return; }
41  
42 sub assignedNodes { return; }
43  
44 # Note: property name is inherited
45  
46 sub onslotchange : lvalue { return( shift->on( 'slotchange', @_ ) ); }
47  
48 1;
49 # NOTE: POD
50 __END__
51  
52 =encoding utf-8
53  
54 =head1 NAME
55  
56 HTML::Object::DOM::Element::Slot - HTML Object DOM Slot Class
57  
58 =head1 SYNOPSIS
59  
60 use HTML::Object::DOM::Element::Slot;
61 my $slot = HTML::Object::DOM::Element::Slot->new ||
62 die( HTML::Object::DOM::Element::Slot->error, "\n" );
63  
64 =head1 VERSION
65  
66 v0.2.0
67  
68 =head1 DESCRIPTION
69  
70 This interface of the Shadow DOM API enables access to the name and assigned nodes of an HTML C<slot> element.
71  
72 =head1 INHERITANCE
73  
74 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +----------------------------------+
75 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Slot |
76 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +----------------------------------+
77  
78 =head1 PROPERTIES
79  
80 Inherits properties from its parent L<HTML::Object::DOM::Element>
81  
82 =head2 name
83  
84 A string used to get and set the slot's name.
85  
86 Example:
87  
88 my $slots = this->shadowRoot->querySelectorAll('slot');
89 $slots->[1]->addEventListener( slotchange => sub
90 {
91 my $nodes = $slots->[1]->assignedNodes();
92 say( 'Element in Slot "' . $slots->[1]->name . '" changed to "' . $nodes->[0]->outerHTML . '".');
93 });
94  
95 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/name>
96  
97 =head1 METHODS
98  
99 Inherits methods from its parent L<HTML::Object::DOM::Element>
100  
101 =head2 assign
102  
103 Under perl environment, this always returns C<undef>.
104  
105 Under JavaScript, this sets the manually assigned nodes for this slot to the given nodes.
106  
107 Example:
108  
109 sub UpdateDisplayTab
110 {
111 my( $elem, $tabIdx ) = @_;
112 my $shadow = $elem->shadowRoot;
113 my $slot = $shadow->querySelector( 'slot' );
114 my $panels = $elem->querySelectorAll( 'tab-panel' );
115 if( $panels->length && $tabIdx && $tabIdx <= $panels->length )
116 {
117 $slot->assign( $panels->[ $tabIdx - 1 ] );
118 }
119 else
120 {
121 $slot->assign();
122 }
123 }
124  
125 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/assign>
126  
127 =head2 assignedElements
128  
129 Under perl environment, this always returns C<undef>.
130  
131 Under JavaScript, this returns a sequence of the elements assigned to this slot (and no other nodes). If the flatten option is set to true, it also returns the assigned elements of any other slots that are descendants of this slot. If no assigned nodes are found, it returns the slot's fallback content.
132  
133 Example:
134  
135 my $slots = this->shadowRoot->querySelector('slot');
136 my $elements = $slots->assignedElements({ flatten => 1 });
137  
138 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/assignedElements>
139  
140 =head2 assignedNodes
141  
142 Under perl environment, this always returns C<undef>.
143  
144 Under JavaScript, this returns a sequence of the nodes assigned to this slot, and if the flatten option is set to true, the assigned nodes of any other slots that are descendants of this slot. If no assigned nodes are found, it returns the slot's fallback content.
145  
146 Example:
147  
148 my $slots = this->shadowRoot->querySelectorAll('slot');
149 $slots->[1]->addEventListener( slotchange => sub
150 {
151 my $nodes = $slots->[1]->assignedNodes();
152 say( 'Element in Slot "' . $slots->[1]->name . '" changed to "' . $nodes->[0]->outerHTML . '".' );
153 });
154  
155 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/assignedNodes>
156  
157 =head1 EVENTS
158  
159 Event listeners for those events can also be found by prepending C<on> before the event type:
160  
161 For example, C<slotchange> event listeners can be set also with C<onslotchange> method:
162  
163 $e->onslotchange(sub{ # do something });
164 # or as an lvalue method
165 $e->onslotchange = sub{ # do something };
166  
167 =head2 slotchange
168  
169 Fired on an HTMLSlotElement instance (<slot> element) when the node(s) contained in that slot change.
170  
171 Example:
172  
173 my $slots = this->shadowRoot->querySelectorAll('slot');
174 $slots->[1]->addEventListener( slotchange => sub
175 {
176 my $nodes = $slots->[1]->assignedNodes();
177 say( 'Element in Slot "' . $slots->[1]->name . '" changed to "' . $nodes->[0]->outerHTML . '".' );
178 });
179  
180 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/slotchange_event>
181  
182 =head1 AUTHOR
183  
184 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
185  
186 =head1 SEE ALSO
187  
188 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement>, L<Mozilla documentation on slot element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot>
189  
190 =head1 COPYRIGHT & LICENSE
191  
192 Copyright(c) 2022 DEGUEST Pte. Ltd.
193  
194 All rights reserved
195  
196 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
197  
198 =cut