blib/lib/HTML/Object/DOM/FileList.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 32 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
item
2.0
BEGIN
2.0
CRAP 2.0
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 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( Module::Generic::Array );
21 use vars qw( $VERSION );
22 our $VERSION = 'v0.2.0';
23 };
24  
25 use strict;
26 use warnings;
27  
28 sub item { return( shift->index( @_ ) ); }
29  
30 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