| 1 | package HTML::DOM::Event; | ||||||||||
| 2 | |||||||||||
| 3 | 28 | our $VERSION = '0.057'; | |||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 28 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 28 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # Look, TMTOWTDI: | ||||||||||
| 10 | sub CAPTURING_PHASE (){ 1,} | ||||||||||
| 11 | sub AT_TARGET (){ 2,} | ||||||||||
| 12 | sub BUBBLING_PHASE (){ 3,} | ||||||||||
| 13 | |||||||||||
| 14 | 28 | ▶ | use HTML::DOM::Exception 'NOT_SUPPORTED_ERR'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 28 | ▶ | use Exporter 5.57 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 28 | our @EXPORT_OK = qw' | |||||||||
| 18 | CAPTURING_PHASE | ||||||||||
| 19 | AT_TARGET | ||||||||||
| 20 | BUBBLING_PHASE | ||||||||||
| 21 | '; | ||||||||||
| 22 | 28 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||
| 23 | |||||||||||
| 24 | sub new { | ||||||||||
| 25 | 1545 | ▶ | bless {time => time}, $_[0]; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub create_event { | ||||||||||
| 29 | 1546 | ▶ | my $class = class_for($_[0]); | ||||||||
|
Subroutine
create_event: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 30 | 1546 | ▶ | defined $class or die new HTML::DOM::Exception NOT_SUPPORTED_ERR, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | "The event category '$_[0]' is not supported"; | ||||||||||
| 32 | 1545 | (my $path =$class) =~ s/::/\//g; | |||||||||
| 33 | 1545 | require "$path.pm"; | |||||||||
| 34 | 1545 | $class->new | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | # ----------- ATTRIBUTE METHODS ------------- # | ||||||||||
| 38 | # (all read-only) | ||||||||||
| 39 | |||||||||||
| 40 | 1741 | ▶ | sub type { $_[0]{name } } | ||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 41 | 2802 | ▶ | sub target { $_[0]{target }||() } | ||||||||
|
Subroutine
target: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 42 | 24 | ▶ | sub currentTarget { $_[0]{cur_target}||() } | ||||||||
|
Subroutine
currentTarget: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 43 | 1562 | ▶ | sub eventPhase { $_[0]{phase } } | ||||||||
|
Subroutine
eventPhase: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 44 | 1549 | ▶ | sub bubbles { $_[0]{froth } } | ||||||||
|
Subroutine
bubbles: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 45 | 39 | ▶ | sub cancelable { $_[0]{cancelable} } | ||||||||
|
Subroutine
cancelable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 46 | 1 | ▶ | sub timeStamp { $_[0]{time } } | ||||||||
|
Subroutine
timeStamp: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 47 | 1526 | ▶ | sub cancelled { $_[0]{cancelled } } # non-DOM | ||||||||
|
Subroutine
cancelled: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 48 | 5218 | ▶ | sub propagation_stopped { $_[0]{stopped} } # same hear | ||||||||
|
Subroutine
propagation_stopped: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | # ----------- METHOD METHODS ------------- # | ||||||||||
| 52 | |||||||||||
| 53 | 12 | ▶ | sub stopPropagation { $_[0]{stopped } = !0; return } | ||||||||
|
Subroutine
stopPropagation: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 54 | 12 | ▶ | sub preventDefault { $_[0]{cancelled} = !0 if $_[0]->cancelable; return } | ||||||||
|
Subroutine
preventDefault: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 55 | # similar: | ||||||||||
| 56 | 899 | ▶ | sub _set_eventPhase { $_[0]{phase } = $_[1] } | ||||||||
|
Subroutine
_set_eventPhase: called CC=1 SCAR=0.0
| |||||||||||
| 57 | 1531 | ▶ | sub _set_target { $_[0]{target } = $_[1] } | ||||||||
|
Subroutine
_set_target: called CC=1 SCAR=0.0
| |||||||||||
| 58 | 995 | ▶ | sub _set_currentTarget { $_[0]{cur_target} = $_[1] } | ||||||||
|
Subroutine
_set_currentTarget: called CC=1 SCAR=0.0
| |||||||||||
| 59 | |||||||||||
| 60 | sub initEvent { | ||||||||||
| 61 | shift->init( | ||||||||||
| 62 | 27 | ▶ | type => shift, | ||||||||
|
Subroutine
initEvent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 63 | propagates_up => shift, | ||||||||||
| 64 | cancellable => shift, | ||||||||||
| 65 | ); | ||||||||||
| 66 | 27 | return; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | sub init { | ||||||||||
| 70 | 1547 | ▶ | my($event, %args) = @_; | ||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 71 | 1547 | ▶ | return if defined $event->eventPhase; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | @$event{qw/name froth cancelable target/} | ||||||||||
| 73 | 1547 | = @args{qw/ type propagates_up cancellable target /}; | |||||||||
| 74 | 1547 | $event; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | # ----------- OTHER STUFF ------------- # | ||||||||||
| 78 | |||||||||||
| 79 | # ~~~ Should I document these? | ||||||||||
| 80 | # ~~~ If I do make these public, I probably ought to rename them to make | ||||||||||
| 81 | # some distinction between the arg types; the arg to class_for is a DOM | ||||||||||
| 82 | # event module name, and the arg to defaults is an event type. | ||||||||||
| 83 | |||||||||||
| 84 | 28 | my %class_for = ( | |||||||||
| 85 | '' => __PACKAGE__, | ||||||||||
| 86 | UIEvents => 'HTML::DOM::Event::UI', | ||||||||||
| 87 | HTMLEvents => __PACKAGE__, | ||||||||||
| 88 | MouseEvents => 'HTML::DOM::Event::Mouse', | ||||||||||
| 89 | MutationEvents => "HTML::DOM::Event::Mutation", | ||||||||||
| 90 | ); | ||||||||||
| 91 | |||||||||||
| 92 | sub class_for { | ||||||||||
| 93 | 1546 | ▶ | $class_for{$_[0]}; | ||||||||
|
Subroutine
class_for: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | # ~~~ The DOM 2 spec lists mouseover and -out as cancellable. Firefox has | ||||||||||
| 97 | # the cancelable property set to true, but preventDefault does nothing. | ||||||||||
| 98 | # The DOM 3 spec also lists mousemove as cancellable. None of this | ||||||||||
| 99 | # makes any sense. | ||||||||||
| 100 | 28 | my %defaults = ( | |||||||||
| 101 | domfocusin => [ UIEvents => | ||||||||||
| 102 | propagates_up => 1, | ||||||||||
| 103 | cancellable => 0, | ||||||||||
| 104 | ], | ||||||||||
| 105 | domfocusout => [ UIEvents => | ||||||||||
| 106 | propagates_up => 1, | ||||||||||
| 107 | cancellable => 0, | ||||||||||
| 108 | ], | ||||||||||
| 109 | domactivate => [ UIEvents => | ||||||||||
| 110 | propagates_up => 1, | ||||||||||
| 111 | cancellable => 1, | ||||||||||
| 112 | detail => 1, | ||||||||||
| 113 | ], | ||||||||||
| 114 | click => [ MouseEvents => | ||||||||||
| 115 | propagates_up => 1, | ||||||||||
| 116 | cancellable => 1, | ||||||||||
| 117 | detail => 1, | ||||||||||
| 118 | screen_x => 0, | ||||||||||
| 119 | screen_y => 0, | ||||||||||
| 120 | client_x => 0, | ||||||||||
| 121 | client_y => 0, | ||||||||||
| 122 | ctrl => 0, | ||||||||||
| 123 | alt => 0, | ||||||||||
| 124 | shift => 0, | ||||||||||
| 125 | meta => 0, | ||||||||||
| 126 | button => 1, | ||||||||||
| 127 | ], | ||||||||||
| 128 | mousedown => [ MouseEvents => | ||||||||||
| 129 | propagates_up => 1, | ||||||||||
| 130 | cancellable => 1, | ||||||||||
| 131 | detail => 1, | ||||||||||
| 132 | screen_x => 0, | ||||||||||
| 133 | screen_y => 0, | ||||||||||
| 134 | client_x => 0, | ||||||||||
| 135 | client_y => 0, | ||||||||||
| 136 | ctrl => 0, | ||||||||||
| 137 | alt => 0, | ||||||||||
| 138 | shift => 0, | ||||||||||
| 139 | meta => 0, | ||||||||||
| 140 | button => 1, | ||||||||||
| 141 | ], | ||||||||||
| 142 | mouseup => [ MouseEvents => | ||||||||||
| 143 | propagates_up => 1, | ||||||||||
| 144 | cancellable => 1, | ||||||||||
| 145 | detail => 1, | ||||||||||
| 146 | screen_x => 0, | ||||||||||
| 147 | screen_y => 0, | ||||||||||
| 148 | client_x => 0, | ||||||||||
| 149 | client_y => 0, | ||||||||||
| 150 | ctrl => 0, | ||||||||||
| 151 | alt => 0, | ||||||||||
| 152 | shift => 0, | ||||||||||
| 153 | meta => 0, | ||||||||||
| 154 | button => 1, | ||||||||||
| 155 | ], | ||||||||||
| 156 | mouseover => [ MouseEvents => | ||||||||||
| 157 | propagates_up => 1, | ||||||||||
| 158 | cancellable => 1, | ||||||||||
| 159 | screen_x => 0, | ||||||||||
| 160 | screen_y => 0, | ||||||||||
| 161 | client_x => 0, | ||||||||||
| 162 | client_y => 0, | ||||||||||
| 163 | ctrl => 0, | ||||||||||
| 164 | alt => 0, | ||||||||||
| 165 | shift => 0, | ||||||||||
| 166 | meta => 0, | ||||||||||
| 167 | ], | ||||||||||
| 168 | mousemove => [ MouseEvents => | ||||||||||
| 169 | propagates_up => 1, | ||||||||||
| 170 | cancellable => 0, | ||||||||||
| 171 | screen_x => 0, | ||||||||||
| 172 | screen_y => 0, | ||||||||||
| 173 | client_x => 0, | ||||||||||
| 174 | client_y => 0, | ||||||||||
| 175 | ctrl => 0, | ||||||||||
| 176 | alt => 0, | ||||||||||
| 177 | shift => 0, | ||||||||||
| 178 | meta => 0, | ||||||||||
| 179 | ], | ||||||||||
| 180 | mouseout => [ MouseEvents => | ||||||||||
| 181 | propagates_up => 1, | ||||||||||
| 182 | cancellable => 1, | ||||||||||
| 183 | screen_x => 0, | ||||||||||
| 184 | screen_y => 0, | ||||||||||
| 185 | client_x => 0, | ||||||||||
| 186 | client_y => 0, | ||||||||||
| 187 | ctrl => 0, | ||||||||||
| 188 | alt => 0, | ||||||||||
| 189 | shift => 0, | ||||||||||
| 190 | meta => 0, | ||||||||||
| 191 | ], | ||||||||||
| 192 | domsubtreemodified => [ MutationEvents => | ||||||||||
| 193 | propagates_up => 1, | ||||||||||
| 194 | cancellable => 0, | ||||||||||
| 195 | ], | ||||||||||
| 196 | domnodeinserted => [ MutationEvents => | ||||||||||
| 197 | propagates_up => 1, | ||||||||||
| 198 | cancellable => 0, | ||||||||||
| 199 | ], | ||||||||||
| 200 | domnoderemoved => [ MutationEvents => | ||||||||||
| 201 | propagates_up => 1, | ||||||||||
| 202 | cancellable => 0, | ||||||||||
| 203 | ], | ||||||||||
| 204 | domnoderemovedfromdocument => [ MutationEvents => | ||||||||||
| 205 | propagates_up => 0, | ||||||||||
| 206 | cancellable => 0, | ||||||||||
| 207 | ], | ||||||||||
| 208 | domnodeinsertedintodocument => [ MutationEvents => | ||||||||||
| 209 | propagates_up => 0, | ||||||||||
| 210 | cancellable => 0, | ||||||||||
| 211 | ], | ||||||||||
| 212 | domattrmodified => [ MutationEvents => | ||||||||||
| 213 | propagates_up => 1, | ||||||||||
| 214 | cancellable => 0, | ||||||||||
| 215 | ], | ||||||||||
| 216 | domcharacterdatamodified => [ MutationEvents => | ||||||||||
| 217 | propagates_up => 1, | ||||||||||
| 218 | cancellable => 0, | ||||||||||
| 219 | ], | ||||||||||
| 220 | load => [ HTMLEvents => | ||||||||||
| 221 | propagates_up => 0, | ||||||||||
| 222 | cancellable => 0, | ||||||||||
| 223 | ], | ||||||||||
| 224 | unload => [ HTMLEvents => | ||||||||||
| 225 | propagates_up => 0, | ||||||||||
| 226 | cancellable => 0, | ||||||||||
| 227 | ], | ||||||||||
| 228 | focus => [ HTMLEvents => | ||||||||||
| 229 | propagates_up => 0, | ||||||||||
| 230 | cancellable => 0, | ||||||||||
| 231 | ], | ||||||||||
| 232 | blur => [ HTMLEvents => | ||||||||||
| 233 | propagates_up => 0, | ||||||||||
| 234 | cancellable => 0, | ||||||||||
| 235 | ], | ||||||||||
| 236 | abort => [ HTMLEvents => | ||||||||||
| 237 | propagates_up => 1, | ||||||||||
| 238 | cancellable => 0, | ||||||||||
| 239 | ], | ||||||||||
| 240 | error => [ HTMLEvents => | ||||||||||
| 241 | propagates_up => 1, | ||||||||||
| 242 | cancellable => 0, | ||||||||||
| 243 | ], | ||||||||||
| 244 | select => [ HTMLEvents => | ||||||||||
| 245 | propagates_up => 1, | ||||||||||
| 246 | cancellable => 0, | ||||||||||
| 247 | ], | ||||||||||
| 248 | change => [ HTMLEvents => | ||||||||||
| 249 | propagates_up => 1, | ||||||||||
| 250 | cancellable => 0, | ||||||||||
| 251 | ], | ||||||||||
| 252 | # submit uses the defaults | ||||||||||
| 253 | reset => [ HTMLEvents => | ||||||||||
| 254 | propagates_up => 1, | ||||||||||
| 255 | cancellable => 0, | ||||||||||
| 256 | ], | ||||||||||
| 257 | resize => [ HTMLEvents => | ||||||||||
| 258 | propagates_up => 1, | ||||||||||
| 259 | cancellable => 0, | ||||||||||
| 260 | ], | ||||||||||
| 261 | scroll => [ HTMLEvents => | ||||||||||
| 262 | propagates_up => 1, | ||||||||||
| 263 | cancellable => 0, | ||||||||||
| 264 | ], | ||||||||||
| 265 | ); | ||||||||||
| 266 | |||||||||||
| 267 | sub defaults { | ||||||||||
| 268 | 1860 | ▶ | my $evnt_name = lc $_[0]; | ||||||||
|
Subroutine
defaults: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 269 | return exists $defaults{$evnt_name} | ||||||||||
| 270 | 1860 | ▶ | ? @{$defaults{$evnt_name}} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 271 | : (''=>propagates_up=>1,cancellable=>1); | ||||||||||
| 272 | } | ||||||||||
| 273 | |||||||||||
| 274 | # ($event_category, @args) = HTML'DOM'Event'defaults foo; | ||||||||||
| 275 | |||||||||||
| 276 | 28 | 1; | |||||||||
| 277 | __END__ | ||||||||||