Mail::Action::Address - roles applicable to individual addresses


Mail-Action documentation Contained in the Mail-Action distribution.

Index


Code Index:

NAME

Top

Mail::Action::Address - roles applicable to individual addresses

SYNOPSIS

Top

    use Mail::Action::Address;

    use Class::Roles
        does => 'address_expires',
        does => 'address_named',
        does => 'address_described';

DESCRIPTION

Top

Most Mail::Action users operate around the idea of unique, lightweight e-mail addresses, whether unique names within a subdomain, uniquely keyed variants of a single address, or some combination of the two.

This class defines certain behavior and data storage features of those addresses. Use Class::Roles to add these features to your own Address classes.

ROLES

Top

address_expires

Allows Address instances to have an optional expiration date. This adds two method to the class to which you apply it:

expires( $timestring )

Gets and sets the time at which this Address will expire. Set this time in a simple text string, such as 7d2h. Valid time units are:

* m, for minute. This is sixty (60) seconds.
* h, for hour. This is sixty (60) minutes.
* d, for day. This is twenty-four (24) hours.
* w, for week. This is seven (7) days.
* M, for month. This is thirty (30) days.

The returned time is in epoch seconds.

* process_time( $timestring )

Turns a $timestring into the number of seconds it represents.

address_named

Allows Address instances to have a name. This adds one method to the class to which you apply it:

name( $name )

Gets and sets the name associated with this Address. This method strips the name of all non-alphanumeric characters, including spaces and punctuation.

address_described

Allows Address instances to have a one-sentence description. This adds one method to the class to which you apply it:

description( $description )

Gets and sets the description of this Address. This will return the empty string if there is no description.

AUTHOR

Top

chromatic, chromatic at wgz dot org

BUGS

Top

No known bugs.

SEE ALSO

Top

Class::Roles, Mail::TempAddress::Address, Mail::SimpleList::Alias.

COPYRIGHT

Top


Mail-Action documentation Contained in the Mail-Action distribution.

package Mail::Action::Address;

use strict;
use warnings;

use vars '$VERSION';
$VERSION = '0.46';

use Class::Roles multi =>
{
    address_expires    => [qw( expires process_time )],
    address_named      => [qw( name )],
    address_described  => [qw( description )],
};

sub description
{
    my $self             = shift;
    $self->{description} = shift if @_;

    return '' unless exists $self->{description};
    return                  $self->{description};
}

sub name
{
    my $self       = shift;
    ($self->{name} = shift) =~ tr/-A-Za-z0-9_//cd if @_;
    return $self->{name};
}

sub expires
{
    my $self = shift;
    $self->{expires} = $self->process_time( shift ) + time() if @_;
    $self->{expires} = 0 unless $self->{expires};
    return $self->{expires};
}

sub process_time
{
    my ($self, $time) = @_;
    return $time unless $time =~ tr/0-9//c;

    my %times = (
        m =>                60,
        h =>           60 * 60,
        d =>      24 * 60 * 60,
        w =>  7 * 24 * 60 * 60,
        M => 30 * 24 * 60 * 60,
    );

    my $units    = join('', keys %times);
    my $seconds;

    while ( $time =~ s/(\d+)([$units])// )
    {
        $seconds += $1 * $times{ $2 };
    }

    return $seconds;
}

1;
__END__