| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ## Lightweight DateTime Alternative - ~/lib/DateTime/Lite/Exception.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Version v0.1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2026 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ## Created 2026/04/03 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ## Modified 2026/04/10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 DateTime::Lite::Exception; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=14.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use v5.10.1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | ▶ | if( $] < 5.013 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | unless( defined( &warnings::register_categories ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | *warnings::_mkMask = sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $bit = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $mask = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | vec( $mask, $bit, 1 ) = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | return( $mask ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | *warnings::register_categories = sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my @names = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | foreach my $name ( @names ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if( !defined( $warnings::Bits{ $name } ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $warnings::Offsets{ $name } = $warnings::LAST_BIT; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $warnings::Bits{ $name } = warnings::_mkMask( $warnings::LAST_BIT++ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $warnings::DeadBits{ $name } = warnings::_mkMask( $warnings::LAST_BIT++ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if( length( $warnings::Bits{ $name } ) > length( $warnings::Bits{all} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $warnings::Bits{all} .= "\x55"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $warnings::DeadBits{all} .= "\xaa"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 11 | warnings::register_categories( 'DateTime::Lite' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 11 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 11 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | '""' => \&as_string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | bool => sub{1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 11 | fallback => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 11 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 25 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=36.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 25 | my $this = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 25 | ▶ | my $class = ref( $this ) || $this; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 25 | my %args; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 25 | ▶ | if( @_ == 1 && ref( $_[0] ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 25 | %args = %{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | elsif( @_ % 2 == 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $args{message} = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | my $self = bless( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | message => $args{message} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | package => $args{package} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | file => $args{file} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | line => $args{line} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 25 | ▶ | skip_frames => $args{skip_frames} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%5/10
$args{"message"} // ""
$args{"package"} // ""
$args{"file"} // ""
$args{"line"} // ""
$args{"skip_frames"} // 0
MC/DC0%0/1
$args{"message"} // ""
$args{"message"}
MC/DC0%0/1
$args{"package"} // ""
$args{"package"}
MC/DC0%0/1
$args{"file"} // ""
$args{"file"}
MC/DC0%0/1
$args{"line"} // ""
$args{"line"}
MC/DC0%0/1
$args{"skip_frames"} // 0
$args{"skip_frames"}
Truth table50%1/2
A
A= $args{"message"}
Truth table50%1/2
A
A= $args{"package"}
Truth table50%1/2
A
A= $args{"file"}
Truth table50%1/2
A
A= $args{"line"}
Truth table50%1/2
A
A= $args{"skip_frames"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | }, $class ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Auto-populate call location unless provided | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 25 | ▶ | unless( $self->{file} && $self->{line} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"file"} and $self->{"line"}
MC/DC0%0/2
$self->{"file"} and $self->{"line"}
$self->{"file"}
$self->{"line"}
Truth table33%1/3
A and B
A= $self->{"file"}B= $self->{"line"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 25 | my $skip = $self->{skip_frames} + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 25 | my @info = caller( $skip ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 25 | ▶ | if( @info ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 25 | ▶ | $self->{package} ||= $info[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"package"} ||= $info[0]
MC/DC0%0/2
$self->{"package"} ||= $info[0]
$self->{"package"}
$info[0]
Truth table33%1/3
A ||= B
A= $self->{"package"}B= $info[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 25 | ▶ | $self->{file} ||= $info[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"file"} ||= $info[1]
MC/DC0%0/2
$self->{"file"} ||= $info[1]
$self->{"file"}
$info[1]
Truth table33%1/3
A ||= B
A= $self->{"file"}B= $info[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 25 | ▶ | $self->{line} ||= $info[2]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"line"} ||= $info[2]
MC/DC0%0/2
$self->{"line"} ||= $info[2]
$self->{"line"}
$info[2]
Truth table33%1/3
A ||= B
A= $self->{"line"}B= $info[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 25 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | sub as_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 22 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=5 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 22 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 22 | ▶ | my $msg = $self->{message} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"message"} // ""
MC/DC0%0/1
$self->{"message"} // ""
$self->{"message"}
Truth table50%1/2
A
A= $self->{"message"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 22 | ▶ | if( $self->{file} && $self->{line} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"file"} and $self->{"line"}
MC/DC0%0/2
$self->{"file"} and $self->{"line"}
$self->{"file"}
$self->{"line"}
Truth table33%1/3
A and B
A= $self->{"file"}B= $self->{"line"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | $msg .= sprintf( " at %s line %d.\n", $self->{file}, $self->{line} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 22 | ▶ | unless( $msg =~ /\n\z/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 22 | return( $msg ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub file { return( $_[0]->{file} ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub line { return( $_[0]->{line} ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub message { return( $_[0]->{message} ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub package { return( $_[0]->{package} ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
package: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | sub throw | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | my $class = ref( $_[0] ) ? ref( shift( @_ ) ) : shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $e = $class->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | die( $e ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||