Mail/Make/Headers/MessageID.pm

filter: Statementstmt 50.8% 31 / 61 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 52.6% 10 / 19 Podpod 71.4% 5 / 7 totaltotal 43.8% 46 / 105 CC 8 SCAR 21.4
CC
8
Cov
41%
init
30.0
id
12.0
as_string
6.0
CRAP 8.5
« Mail/Make/Headers/Generic.pm ↑ Summary MM/Table.pm »
1 ##----------------------------------------------------------------------------
2 ## MIME Email Builder - ~/lib/Mail/Make/Headers/MessageID.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2026/03/02
7 ## Modified 2026/03/03
8 ## All rights reserved.
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Mail::Make::Headers::MessageID;
14 BEGIN
15 9 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 warnings::register_categories( 'Mail::Make' );
19 9 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 9 ▶ use vars qw( $VERSION $EXCEPTION_CLASS );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 9 ▶ use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 9 ▶ use Mail::Make::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 use overload
24 9 ▶ (
Subroutine BEGIN: called CC=1 SCAR=0.2
25 '""' => 'as_string',
26 0 ▶ bool => sub { 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 9 );
28 9 our $EXCEPTION_CLASS = 'Mail::Make::Exception';
29 9 our $VERSION = 'v0.2.0';
30 };
31  
32 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 sub init
36 0 ▶{
Subroutine init: not called CC=5 SCAR=34.0
Pod documented
37 0 my $self = shift( @_ );
38 0 $self->{_id} = undef;
39 0 $self->{_exception_class} = $EXCEPTION_CLASS;
40 0 my $id = shift( @_ );
41 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
42 0 ▶ if( defined( $id ) && length( $id ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and length $id) { } 0 0 0
Condition0%0/3
defined $id and length $id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $id and length $id
defined $id length $id
Truth table0%0/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
43 {
44 0 ▶ $self->id( $id ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->id($id) or return $self->pass_error 0 0 0
45 }
46 else
47 {
48 0 $self->{_id} = $self->_generate;
49 }
50 0 return( $self );
51 }
52  
53 sub as_string
54 0 ▶{
Subroutine as_string: not called CC=2 SCAR=17.9
Pod documented
55 0 my $self = shift( @_ );
56 0 ▶ return( $self->{_id} // '' );
Condition0%0/2
$self->{"_id"} // ""
l!l
00
MC/DC0%0/1
$self->{"_id"} // ""
$self->{"_id"}
Truth table0%0/2
A
A= $self->{"_id"}
Aresult
11
00
57 }
58  
59 # generate()
60 # Generates a new unique Message-ID string and sets it.
61 sub generate
62 0 ▶{
Subroutine generate: not called CC=1 SCAR=6.9
Pod documented
63 0 my $self = shift( @_ );
64 0 $self->{_id} = $self->_generate;
65 0 return( $self );
66 }
67  
68 # id( [$value] )
69 # Gets or sets the Message-ID string. Must be in angle-bracket format
70 # <local-part@domain> per RFC 2822.
71 sub id
72 0 ▶{
Subroutine id: not called CC=3 SCAR=24.8
Pod documented
73 0 my $self = shift( @_ );
74 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
75 {
76 0 my $val = shift( @_ );
77 0 ▶ unless( $val =~ /\A<[^>]+\@[^>]+>\z/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($val =~ /\A<[^>]+\@[^>]+>\z/) 0 0 0
78 {
79 0 return( $self->error( "Message-ID must be in <local\@domain> format, got: '$val'" ) );
80 }
81 0 $self->{_id} = $val;
82 0 return( $self );
83 }
84 0 return( $self->{_id} );
85 }
86  
87 # value() is an alias for as_string
88 0 ▶sub value { return( shift->as_string ); }
Subroutine value: not called CC=1 SCAR=6.9
Pod documented
89  
90 # _generate()
91 # Produces a unique <uuid@generated> string.
92 sub _generate
93 0 ▶{
Subroutine _generate: not called CC=1 SCAR=6.9
94 0 my $self = shift( @_ );
95 0 my $uuid = lc( Data::UUID->new->create_str );
96 0 $uuid =~ tr/-//d;
97 0 return( "<${uuid}\@mail.make.generated>" );
98 }
99  
100 # NOTE: STORABLE support
101 0 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
102  
103 0 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
104  
105 9 1;
106 # NOTE: POD
107 __END__
« Mail/Make/Headers/Generic.pm ↑ Summary MM/Table.pm »