lib/DateTime/Lite/Exception.pm

filter: Statementstmt 61.1% 41 / 67 Branchbran 27.2% 6 / 22 Conditioncond 39.3% 13 / 33 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 52.9% 9 / 17 Podpod 100% 7 / 7 totaltotal 45.7% 76 / 166 CC 26 SCAR 29.3
CC
26
Cov
49%
new
39.8
__ANON__
20.0
as_string
6.1
CRAP 18.8
« lib/DateTime/Lite.pm ↑ Summary lib/DateTime/Lite/Infinite.pm »
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
BranchTrueFalseTotal
if ($] < "5.013") 0 11 11
21 {
22 11 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 0 ▶ unless( defined( &warnings::register_categories ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &warnings::register_categories) 0 0 0
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
BranchTrueFalseTotal
unless (defined $warnings::Bits{$name}) 0 0 0
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
BranchTrueFalseTotal
if (length $warnings::Bits{$name} > length $warnings::Bits{"all"}) 0 0 0
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
l!l&&r!l&&!r
0250
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
67 25 my %args;
68 25 ▶ if( @_ == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 25 0 25
elsif (@_ % 2 == 0) { } 0 0 0
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
0025
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"
ABresult
0X0
100
111
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"} // ""
l!l
250
$args{"package"} // ""
l!l
025
$args{"file"} // ""
l!l
025
$args{"line"} // ""
l!l
025
$args{"skip_frames"} // 0
l!l
250
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"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"package"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"file"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"line"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"skip_frames"}
Aresult
11
00
88 }, $class );
89  
90 # Auto-populate call location unless provided
91 25 ▶ unless( $self->{file} && $self->{line} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"file"} and $self->{"line"}) 25 0 25
Condition33%1/3
$self->{"file"} and $self->{"line"}
!ll&&!rl&&r
2500
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"}
ABresult
0X0
100
111
92 {
93 25 my $skip = $self->{skip_frames} + 1;
94 25 my @info = caller( $skip );
95 25 ▶ if( @info )
Branch: 1 branch
BranchTrueFalseTotal
if (@info) 25 0 25
96 {
97 25 ▶ $self->{package} ||= $info[0];
Condition33%1/3
$self->{"package"} ||= $info[0]
l!l&&r!l&&!r
0250
MC/DC0%0/2
$self->{"package"} ||= $info[0]
$self->{"package"} $info[0]
Truth table33%1/3
A ||= B
A= $self->{"package"}B= $info[0]
ABresult
1X1
011
000
98 25 ▶ $self->{file} ||= $info[1];
Condition33%1/3
$self->{"file"} ||= $info[1]
l!l&&r!l&&!r
0250
MC/DC0%0/2
$self->{"file"} ||= $info[1]
$self->{"file"} $info[1]
Truth table33%1/3
A ||= B
A= $self->{"file"}B= $info[1]
ABresult
1X1
011
000
99 25 ▶ $self->{line} ||= $info[2];
Condition33%1/3
$self->{"line"} ||= $info[2]
l!l&&r!l&&!r
0250
MC/DC0%0/2
$self->{"line"} ||= $info[2]
$self->{"line"} $info[2]
Truth table33%1/3
A ||= B
A= $self->{"line"}B= $info[2]
ABresult
1X1
011
000
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"} // ""
l!l
220
MC/DC0%0/1
$self->{"message"} // ""
$self->{"message"}
Truth table50%1/2
A
A= $self->{"message"}
Aresult
11
00
109 22 ▶ if( $self->{file} && $self->{line} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"file"} and $self->{"line"}) 22 0 22
Condition33%1/3
$self->{"file"} and $self->{"line"}
!ll&&!rl&&r
0022
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"}
ABresult
0X0
100
111
110 {
111 $msg .= sprintf( " at %s line %d.\n", $self->{file}, $self->{line} )
112 22 ▶ unless( $msg =~ /\n\z/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $msg =~ /\n\z/ 22 0 22
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
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
125 0 my $e = $class->new( @_ );
126 0 die( $e );
127 }
128  
129 11 1;
130 # NOTE: POD
131 __END__
« lib/DateTime/Lite.pm ↑ Summary lib/DateTime/Lite/Infinite.pm »