| 1 | ##---------------------------------------------------------------------------- | ||
| 2 | ## MIME Email Builder - ~/lib/Mail/Make/Body.pm | ||
| 3 | ## Version v0.1.0 | ||
| 4 | ## Copyright(c) 2026 DEGUEST Pte. Ltd. | ||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||
| 6 | ## Created 2026/03/02 | ||
| 7 | ## Modified 2026/03/02 | ||
| 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::Body; | ||
| 14 | BEGIN | ||
| 15 | { | ||
| 16 | use strict; | ||
| 17 | use warnings; | ||
| 18 | warnings::register_categories( 'Mail::Make' ); | ||
| 19 | use parent qw( Module::Generic ); | ||
| 20 | use vars qw( $VERSION $EXCEPTION_CLASS ); | ||
| 21 | use Mail::Make::Exception; | ||
| 22 | our $EXCEPTION_CLASS = 'Mail::Make::Exception'; | ||
| 23 | our $VERSION = 'v0.1.0'; | ||
| 24 | }; | ||
| 25 | |||
| 26 | use strict; | ||
| 27 | use warnings; | ||
| 28 | |||
| 29 | # Returns the body content as a scalar ref. | ||
| 30 | # Must be overridden by subclasses. | ||
| 31 | sub as_string | ||
| 32 | { | ||
| 33 | my $self = shift( @_ ); | ||
| 34 | return( $self->error( ref( $self ) . "::as_string() is not implemented." ) ); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub data { return( shift->as_string( @_ ) ); } | ||
| 38 | |||
| 39 | # Returns the byte length of the body content. | ||
| 40 | sub length | ||
| 41 | { | ||
| 42 | my $self = shift( @_ ); | ||
| 43 | my $string = $self->as_string || return( $self->pass_error ); | ||
| 44 | return( CORE::length( $$string ) ); | ||
| 45 | } | ||
| 46 | |||
| 47 | # Returns true if the body is stored on disk (Body::File), false otherwise. | ||
| 48 | sub is_on_file { return(0); } | ||
| 49 | |||
| 50 | # Returns true if the body is stored in memory (Body::InCore), false otherwise. | ||
| 51 | sub is_in_core { return(0); } | ||
| 52 | |||
| 53 | # path() - only meaningful for Body::File; returns undef here. | ||
| 54 | sub path { return; } | ||
| 55 | |||
| 56 | # Empties / releases the body content. Subclasses override. | ||
| 57 | sub purge { return( shift ); } | ||
| 58 | |||
| 59 | # NOTE: STORABLE support | ||
| 60 | sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); } | ||
| 61 | |||
| 62 | sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); } | ||
| 63 | |||
| 64 | 1; | ||
| 65 | # NOTE: POD | ||
| 66 | __END__ |