| 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 | 2 | ▶ | { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 2 | warnings::register_categories( 'HTML::Object' ); | |||||||||||
| 20 | 2 | ▶ | use parent qw( Module::Generic::File ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 2 | ▶ | use vars qw( $VERSION ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 2 | ▶ | use DateTime::Format::Lite; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | 2 | ▶ | use Module::Generic::Scalar; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 2 | our $VERSION = 'v0.2.1'; | |||||||||||
| 25 | }; | ||||||||||||
| 26 | |||||||||||||
| 27 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | |||||||||||||
| 30 | sub arrayBuffer | ||||||||||||
| 31 | 1 | ▶ | { | ||||||||||
|
Subroutine
arrayBuffer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 32 | 1 | my $self = shift( @_ ); | |||||||||||
| 33 | 1 | my $data = $self->load({ binmode => 'raw' }); | |||||||||||
| 34 | 1 | return( Module::Generic::Scalar->new( \$data ) ); | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | sub lastModified | ||||||||||||
| 38 | 1 | ▶ | { | ||||||||||
|
Subroutine
lastModified: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 39 | 1 | my $self = shift( @_ ); | |||||||||||
| 40 | 1 | my $dt = $self->mtime; | |||||||||||
| 41 | 1 | my $fmt = DateTime::Format::Lite->new( pattern => '%s' ); | |||||||||||
| 42 | 1 | $dt->set_formatter( $fmt ); | |||||||||||
| 43 | 1 | return( $dt ); | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 1 | ▶ | sub lastModifiedDate { return( shift->mtime ); } | ||||||||||
|
Subroutine
lastModifiedDate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 47 | |||||||||||||
| 48 | 1 | ▶ | sub name { return( shift->basename ); } | ||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 49 | |||||||||||||
| 50 | # Note: sub size is inherited | ||||||||||||
| 51 | |||||||||||||
| 52 | sub slice | ||||||||||||
| 53 | 1 | ▶ | { | ||||||||||
|
Subroutine
slice: called CC=10 SCAR=26.6
Pod
documented
| |||||||||||||
| 54 | 1 | my $self = shift( @_ ); | |||||||||||
| 55 | 1 | my( $start, $end ) = @_; | |||||||||||
| 56 | 1 | ▶ | return( $self->error( "start value provided is not an integer." ) ) if( !$self->_is_integer( $start ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 1 | ▶ | $end = $self->size if( !$self->_is_integer( $end ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 1 | ▶ | return( Module::Generic::Scalar->new ) if( $end <= $start ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | 1 | my $len = $end - $start; | |||||||||||
| 60 | 1 | my $opened = $self->opened; | |||||||||||
| 61 | 1 | my $io; | |||||||||||
| 62 | my $pos; | ||||||||||||
| 63 | 1 | ▶ | if( $opened ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | { | ||||||||||||
| 65 | 0 | $io = $opened; | |||||||||||
| 66 | 0 | $pos = $io->seek(0,1); | |||||||||||
| 67 | } | ||||||||||||
| 68 | else | ||||||||||||
| 69 | { | ||||||||||||
| 70 | 1 | ▶ | $io = $self->open({ binmode => 'utf-8' }) || return( $self->pass_error ); | ||||||||||
|
Condition50%1/2
$self->open({'binmode', 'utf-8'}) || (return $self->pass_error)
MC/DC0%0/1
$self->open({'binmode', 'utf-8'}) || (return $self->pass_error)
$self->open({'binmode', 'utf-8'})
Truth table50%1/2
A
A= $self->open({'binmode', 'utf-8'})
| |||||||||||||
| 71 | } | ||||||||||||
| 72 | 1 | ▶ | $io->seek( $start, 0 ) || return( $self->pass_error ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | 1 | my $data; | |||||||||||
| 74 | 1 | ▶ | $self->read( $data, $len ) || return( $self->pass_error ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | 1 | ▶ | if( $opened ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | { | ||||||||||||
| 77 | 0 | ▶ | $io->seek( $pos, 0 ) if( defined( $pos ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | } | ||||||||||||
| 79 | else | ||||||||||||
| 80 | { | ||||||||||||
| 81 | 1 | $self->close; | |||||||||||
| 82 | } | ||||||||||||
| 83 | 1 | return( Module::Generic::Scalar->new( \$data ) ); | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 1 | ▶ | sub stream { return( shift->open( @_ ) ); } | ||||||||||
|
Subroutine
stream: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 87 | |||||||||||||
| 88 | sub text | ||||||||||||
| 89 | 1 | ▶ | { | ||||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 90 | 1 | my $self = shift( @_ ); | |||||||||||
| 91 | 1 | my $data = $self->load_utf8; | |||||||||||
| 92 | 1 | return( Module::Generic::Scalar->new( \$data ) ); | |||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | 1 | ▶ | sub type { return( shift->finfo->mime_type ); } | ||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 96 | |||||||||||||
| 97 | 1 | ▶ | sub webkitRelativePath { return( shift->relative ); } | ||||||||||
|
Subroutine
webkitRelativePath: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 98 | |||||||||||||
| 99 | 2 | 1; | |||||||||||
| 100 | # NOTE: POD | ||||||||||||
| 101 | __END__ | ||||||||||||