TipJar-MTA-queue
view release on metacpan or search on metacpan
package TipJar::MTA::queue;
use 5.006;
use strict;
use warnings;
use Carp;
use vars qw/$VERSION $basedir $tally/;
$VERSION = '0.02';
$tally = 'a';
# use TipJar::fields qw/RA targetlist body/;
sub RA(){0};
sub targetlist(){1};
sub body(){2};
# humbug
# use Fcntl ':flock';
sub FLOCK_EX(){2};
sub FLOCK_UN(){8};
sub new{
bless [undef,[],''];
};
sub import{
shift;
$basedir = shift;
-d $basedir or croak "[$basedir] is no directory";
-w $basedir or croak "[$basedir] is not writable";
};
sub return_address{
# set the RA field
$_[0][RA] = $_[1];
1;
};
sub recipient{
# add to the targetlist array
my $obj=shift;
push @{$obj->[targetlist]},@_;
1;
};
sub data{
my $obj = shift;
$obj->[body] = join '',$obj->[body],@_;
1;
};
sub printlist($);
sub printlist($){
# print STDERR "Debug: printlist called with $_[0]\n";
my $x = shift;
if (ref($x)){
my $y;
for $y (@{$x}){
printlist $y;
};
}else{
print MESSAGE "$x\n";
};
};
sub enqueue{
my $obj = shift;
my $name = join '.',time,$$,$tally++,rand(36294626999);
open MESSAGE, ">$basedir/$name"
or croak "could not open [$basedir/$name]: $!";
flock MESSAGE, FLOCK_EX;
print MESSAGE $obj->[RA],"\n";
printlist $obj->[targetlist];
( run in 0.454 second using v1.01-cache-2.11-cpan-524268b4103 )