DTA-CAB

 view release on metacpan or  search on metacpan

CAB/Queue/File.pm  view on Meta::CPAN

sub unlink { $_[0]->delete(); }

1;

##==============================================================================
## Package DTA::CAB::Queue::File::Locked
package DTA::CAB::Queue::File::Locked;
use Fcntl qw(:flock);
our @ISA = qw(DTA::CAB::Queue::File);

sub _locked {
  my $subname = shift;
  my $supersub = DTA::CAB::Queue::File->can($subname);
  die(__PACKAGE__, "::_locked(): no superclass subroutine for '$subname'") if (!$supersub);
  return sub {
    my (@rc);
    flock($_[0]{queue},LOCK_EX) if ($_[0]{queue});
    if (wantarray) {
      @rc = $supersub->(@_);
    } else {
      $rc[0] = $supersub->(@_);
    }
    flock($_[0]{queue},LOCK_UN) if ($_[0]{queue});
    return wantarray ? @rc : $rc[0];
  };
}

*enq = _locked('enq');
*deq = _locked('deq');
*peek = _locked('peek');
*reset = _locked('reset');
#*close = _locked('close');

1; ##-- be happy

__END__



( run in 0.532 second using v1.01-cache-2.11-cpan-49f99fa48dc )