| 1 | ##---------------------------------------------------------------------------- | ||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/FileList.pm | ||
| 3 | ## Version v0.2.0 | ||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||
| 6 | ## Created 2021/12/25 | ||
| 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::FileList; | ||
| 15 | BEGIN | ||
| 16 | { | ||
| 17 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 1 | ▶ | warnings::register_categories( 'HTML::Object' ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 1 | ▶ | use parent qw( Module::Generic::Array ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 1 | ▶ | use vars qw( $VERSION ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 1 | our $VERSION = 'v0.2.0'; | |
| 23 | }; | ||
| 24 | |||
| 25 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 27 | |||
| 28 | 0 | ▶ | sub item { return( shift->index( @_ ) ); } |
|
Subroutine
item: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 29 | |||
| 30 | 1 | 1; | |
| 31 | # NOTE: POD | ||
| 32 | __END__ | ||
| 33 | |||
| 34 | =encoding utf-8 | ||
| 35 | |||
| 36 | =head1 NAME | ||
| 37 | |||
| 38 | HTML::Object::DOM::FileList - HTML Object DOM FileList Class | ||
| 39 | |||
| 40 | =head1 SYNOPSIS | ||
| 41 | |||
| 42 | use HTML::Object::DOM::FileList; | ||
| 43 | my $list = HTML::Object::DOM::FileList->new || | ||
| 44 | die( HTML::Object::DOM::FileList->error, "\n" ); | ||
| 45 | |||
| 46 | <input id="fileItem" type="file" /> | ||
| 47 | my $file = $doc->getElementById('fileItem')->files->[0]; | ||
| 48 | |||
| 49 | =head1 VERSION | ||
| 50 | |||
| 51 | v0.2.0 | ||
| 52 | |||
| 53 | =head1 DESCRIPTION | ||
| 54 | |||
| 55 | An object of this type is returned by the L<HTML::Object::DOM::Element::Input/files> property of the HTML C<<input>> element; this lets you access a list of files you would have set or added, removed, etc.. It inherits from L<Module::Generic::Array> | ||
| 56 | |||
| 57 | Normally, under JavaScript, those files are selected with the C<<input type="file" />> element. It is also used on the web for a list of files dropped into web content when using the drag and drop API; see the L<DataTransfer object on Mozilla|https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer> for details on this usage. | ||
| 58 | |||
| 59 | =head1 PROPERTIES | ||
| 60 | |||
| 61 | =head2 length | ||
| 62 | |||
| 63 | Read-only. | ||
| 64 | |||
| 65 | Returns the number of files in the list. | ||
| 66 | |||
| 67 | =head1 METHODS | ||
| 68 | |||
| 69 | =head2 item | ||
| 70 | |||
| 71 | Returns a L<HTML::Object::DOM::File> object representing the file at the specified index in the file list. | ||
| 72 | |||
| 73 | Example: | ||
| 74 | |||
| 75 | # fileInput is an HTML input element: <input type="file" id="myfileinput" multiple /> | ||
| 76 | my $fileInput = $doc->getElementById("myfileinput"); | ||
| 77 | |||
| 78 | # files is a FileList object (similar to NodeList) | ||
| 79 | my $files = $fileInput->files; | ||
| 80 | my $file; | ||
| 81 | |||
| 82 | # loop through files | ||
| 83 | for( my $i = 0; $i < $files->length; $i++ ) | ||
| 84 | { | ||
| 85 | # get item | ||
| 86 | $file = $files->item($i); | ||
| 87 | # or | ||
| 88 | $file = $files->[$i]; | ||
| 89 | say( $file->name ); | ||
| 90 | } | ||
| 91 | |||
| 92 | =head1 AUTHOR | ||
| 93 | |||
| 94 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||
| 95 | |||
| 96 | =head1 SEE ALSO | ||
| 97 | |||
| 98 | L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/FileList> | ||
| 99 | |||
| 100 | =head1 COPYRIGHT & LICENSE | ||
| 101 | |||
| 102 | Copyright(c) 2021 DEGUEST Pte. Ltd. | ||
| 103 | |||
| 104 | All rights reserved | ||
| 105 | |||
| 106 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 107 | |||
| 108 | =cut | ||