lib/DateTime/Format/Lite/Exception.pm

filter: Statementstmt 73.1% 49 / 67 Branchbran 45.4% 10 / 22 Conditioncond 54.5% 18 / 33 MC/DCmcdc 25.0% 5 / 20 Subroutinesub 82.3% 14 / 17 Podpod 100% 7 / 7 totaltotal 62.0% 103 / 166 CC 26 SCAR 24.6
CC
26
Cov
63%
new
21.8
__ANON__
20.0
as_string
6.1
CRAP 11.7
« lib/DateTime/Format/Lite.pm ↑ Summary DateTime-Format-Lite.xs »
1 ##----------------------------------------------------------------------------
2 ## DateTime Format Lite - ~/lib/DateTime/Format/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/14
7 ## Modified 2026/04/15
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::Format::Lite::Exception;
15 BEGIN
16 7 ▶{
Subroutine BEGIN: called CC=3 SCAR=14.4
17 7 ▶ use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶ if( $] < 5.013 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.013") 0 7 7
21 {
22 7 ▶ 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 7 warnings::register_categories( 'DateTime::Format::Lite' );
54 7 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
55 7 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
56 '""' => \&as_string,
57 2 ▶ bool => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
58 7 fallback => 1,
59 7 );
60 7 our $VERSION = 'v0.1.0';
61 };
62  
63 sub new
64 40 ▶{
Subroutine new: called CC=16 SCAR=30.8
Pod documented
65 40 my $this = shift( @_ );
66 40 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0400
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 40 my %args;
68 40 ▶ if( @_ == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 36 4 40
elsif (@_ % 2 == 0) { } 0 4 4
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
0436
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
69 {
70 36 %args = %{$_[0]};
71 }
72 elsif( @_ % 2 == 0 )
73 {
74 0 %args = @_;
75 }
76 else
77 {
78 4 $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 40 ▶ skip_frames => $args{skip_frames} // 0,
Condition80%8/10
$args{"message"} // ""
l!l
400
$args{"package"} // ""
l!l
040
$args{"file"} // ""
l!l
238
$args{"line"} // ""
l!l
238
$args{"skip_frames"} // 0
l!l
346
MC/DC0%0/1
$args{"message"} // ""
$args{"message"}
MC/DC0%0/1
$args{"package"} // ""
$args{"package"}
MC/DC100%1/1
$args{"file"} // ""
$args{"file"}
MC/DC100%1/1
$args{"line"} // ""
$args{"line"}
MC/DC100%1/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 table100%2/2
A
A= $args{"file"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"line"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"skip_frames"}
Aresult
11
00
88 }, $class );
89  
90 # Auto-populate call location unless provided
91 40 ▶ unless( $self->{file} && $self->{line} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"file"} and $self->{"line"}) 38 2 40
Condition66%2/3
$self->{"file"} and $self->{"line"}
!ll&&!rl&&r
3802
MC/DC50%1/2
$self->{"file"} and $self->{"line"}
$self->{"file"} $self->{"line"}
Truth table66%2/3
A and B
A= $self->{"file"}B= $self->{"line"}
ABresult
0X0
100
111
92 {
93 38 my $skip = $self->{skip_frames} + 1;
94 38 my @info = caller( $skip );
95 38 ▶ if( @info )
Branch: 1 branch
BranchTrueFalseTotal
if (@info) 38 0 38
96 {
97 38 ▶ $self->{package} ||= $info[0];
Condition33%1/3
$self->{"package"} ||= $info[0]
l!l&&r!l&&!r
0380
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 38 ▶ $self->{file} ||= $info[1];
Condition33%1/3
$self->{"file"} ||= $info[1]
l!l&&r!l&&!r
0380
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 38 ▶ $self->{line} ||= $info[2];
Condition33%1/3
$self->{"line"} ||= $info[2]
l!l&&r!l&&!r
0380
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 40 return( $self );
103 }
104  
105 sub as_string
106 2 ▶{
Subroutine as_string: called CC=5 SCAR=18.1
Pod documented
107 2 my $self = shift( @_ );
108 2 ▶ my $msg = $self->{message} // '';
Condition50%1/2
$self->{"message"} // ""
l!l
20
MC/DC0%0/1
$self->{"message"} // ""
$self->{"message"}
Truth table50%1/2
A
A= $self->{"message"}
Aresult
11
00
109 2 ▶ if( $self->{file} && $self->{line} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"file"} and $self->{"line"}) 2 0 2
Condition33%1/3
$self->{"file"} and $self->{"line"}
!ll&&!rl&&r
002
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 2 ▶ unless( $msg =~ /\n\z/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $msg =~ /\n\z/ 2 0 2
113 }
114 2 return( $msg );
115 }
116  
117 3 ▶sub file { return( $_[0]->{file} ); }
Subroutine file: called CC=1 SCAR=0.0
Pod documented
118 3 ▶sub line { return( $_[0]->{line} ); }
Subroutine line: called CC=1 SCAR=0.0
Pod documented
119 28 ▶sub message { return( $_[0]->{message} ); }
Subroutine message: called CC=1 SCAR=0.0
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 1 ▶{
Subroutine throw: called CC=2 SCAR=7.1
Pod documented
124 1 ▶ my $class = ref( $_[0] ) ? ref( shift( @_ ) ) : shift( @_ );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1 1
125 1 my $e = $class->new( @_ );
126 1 die( $e );
127 }
128  
129 7 1;
130 # NOTE: POD
131 __END__
« lib/DateTime/Format/Lite.pm ↑ Summary DateTime-Format-Lite.xs »