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

filter: Statementstmt 0.0% 0 / 65 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 111 CC 7 SCAR 28.8
CC
7
Cov
0%
slice
56.0
BEGIN
2.0
arrayBuffer
2.0
CRAP 17.8
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/File.pm
3 ## Version v0.2.1
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/25
7 ## Modified 2026/07/04
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::File;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( Module::Generic::File );
21 use vars qw( $VERSION );
22 use DateTime::Format::Lite;
23 use Module::Generic::Scalar;
24 our $VERSION = 'v0.2.1';
25 };
26  
27 use strict;
28 use warnings;
29  
30 sub arrayBuffer
31 {
32 my $self = shift( @_ );
33 my $data = $self->load({ binmode => 'raw' });
34 return( Module::Generic::Scalar->new( \$data ) );
35 }
36  
37 sub lastModified
38 {
39 my $self = shift( @_ );
40 my $dt = $self->mtime;
41 my $fmt = DateTime::Format::Lite->new( pattern => '%s' );
42 $dt->set_formatter( $fmt );
43 return( $dt );
44 }
45  
46 sub lastModifiedDate { return( shift->mtime ); }
47  
48 sub name { return( shift->basename ); }
49  
50 # Note: sub size is inherited
51  
52 sub slice
53 {
54 my $self = shift( @_ );
55 my( $start, $end ) = @_;
56 return( $self->error( "start value provided is not an integer." ) ) if( !$self->_is_integer( $start ) );
57 $end = $self->size if( !$self->_is_integer( $end ) );
58 return( Module::Generic::Scalar->new ) if( $end <= $start );
59 my $len = $end - $start;
60 my $opened = $self->opened;
61 my $io;
62 my $pos;
63 if( $opened )
64 {
65 $io = $opened;
66 $pos = $io->seek(0,1);
67 }
68 else
69 {
70 $io = $self->open({ binmode => 'utf-8' }) || return( $self->pass_error );
71 }
72 $io->seek( $start, 0 ) || return( $self->pass_error );
73 my $data;
74 $self->read( $data, $len ) || return( $self->pass_error );
75 if( $opened )
76 {
77 $io->seek( $pos, 0 ) if( defined( $pos ) );
78 }
79 else
80 {
81 $self->close;
82 }
83 return( Module::Generic::Scalar->new( \$data ) );
84 }
85  
86 sub stream { return( shift->open( @_ ) ); }
87  
88 sub text
89 {
90 my $self = shift( @_ );
91 my $data = $self->load_utf8;
92 return( Module::Generic::Scalar->new( \$data ) );
93 }
94  
95 sub type { return( shift->finfo->mime_type ); }
96  
97 sub webkitRelativePath { return( shift->relative ); }
98  
99 1;
100 # NOTE: POD
101 __END__