WWW::Ebay::Status - encapsulate auction status


WWW-Ebay documentation Contained in the WWW-Ebay distribution.

Index


Code Index:

NAME

Top

WWW::Ebay::Status -- encapsulate auction status

SYNOPSIS

Top

  use WWW::Ebay::Status;
  my $oStatus = new WWW::Ebay::Status;

DESCRIPTION

Top

A convenience class for keeping track of the status of one auction, such as an auction you are selling on www.ebay.com

The status of an auction consists of several yes/no flags. Each yes/no flag indicates whether a certain operation has been performed on this auction. The available flags are described below under FLAGS.

BUGS

Top

Please tell the author if you find any.

METHODS

Top

new

Creates and returns a new Status object. All status flags are 'off'.

new_from_integer

Creates and returns a new Status object, with all values derived from the given integer. (Most likely, the integer was obtained by calling as_integer() on another WWW::Ebay::Status object.) Useful as a Thaw method.

reset

Set all flags to false.

any_local_actions

Consider that this Status object refers to auction X. This method returns true if any operations have been performed on auction X after it has ended.

as_text

Returns a human-readable description of all the set flags.

as_integer

Returns an integer representation of the status bits. Useful as a Freeze method.

FLAGS

Top

These are the yes/no flags that apply to an auction. They all act as get/set methods: give an argument to set the value; give no arguments to get the value.

listed

I.e. this auction has been uploaded to eBay and is underway.

ended

I.e. bidding is closed.

congratulated

I.e. we have sent a "Congratulations, please pay me now" email.

payment_cleared
shipped
received
left_feedback
got_feedback
archived

E.g. all actions are done, don't show this auction any more.

AUTHOR

Top

Martin 'Kingpin' Thurn, mthurn at cpan.org, http://tinyurl.com/nn67z.

COPYRIGHT

Top


WWW-Ebay documentation Contained in the WWW-Ebay distribution.
# $rcs = ' $Id: Status.pm,v 1.17 2010-03-06 13:33:22 Martin Exp $ ' ;

package WWW::Ebay::Status;

use strict;
use warnings;

my
$VERSION = do { my @r = (q$Revision: 1.17 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };

# We use a bitvector for simplicity, even though many of the states
# are mutually exclusive.

use Bit::Vector;
use Carp qw( carp cluck );
use Data::Dumper; # for debugging only

# These constants return the bit position of the yes/no value:
use constant ONLINED => 0;  # Have we posted the auction, or is it in
                            # the "outbox"?
use constant ALLOVER => 1;  # Has the auction ended, or still in progress?
use constant CONGRAT => 2;  # Have we sent congrats email to the buyer?
use constant GOTPAID => 3;  # Have we received payment?
use constant CLEARED => 4;  # Has the check cleared?
use constant SHIPPED => 5;  # Have we shipped the item?
use constant SHIPACK => 6;  # Has buyer informed us that item was received?
use constant FEDBACK => 7;  # Have we sent feedback to buyer?  Outbox == sent
use constant EATBACK => 8;  # Has the buyer left feedback for us?
use constant ARCHIVE => 30;  # This is a huge number because it's
                             # pretty much the last thing anybody can
                             # ever do with an auction

my $iNumBits = 32;

sub new
  {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  unless ($class)
    {
    carp "You can not call new like that";
    $class = 'FAIL';
    } # unless
  my $oVector = new Bit::Vector($iNumBits);
  my $self  = {
               _vec => $oVector,
              };
  return bless ($self, $class);
  } # new

sub new_from_integer
  {
  # die sprintf(" + this is %s::new_from_integer(@_)\n", __PACKAGE__);
  my $arg = shift;
  # If this was called as a method, the integer is the second
  # argument:
  $arg = shift if (
                   # This lets them call it as new_from_integer WWW::Ebay::Status(0):
                   # Or as WWW::Ebay::Status::new_from_integer(0):
                   ($arg eq __PACKAGE__)
                   ||
                   # This lets them call it as $o->new_from_integer(0):
                   (ref($arg) eq __PACKAGE__)
                  );
  # If arg is missing or undef, use zero:
  $arg ||= 0;
  # Create a new object:
  my $self = &new(__PACKAGE__);
  # No error-checking here; ASSume that $arg is something that
  # Bit::Vector sees as a decimal integer:
  $self->{_vec}->from_Dec($arg);
  return $self;
  } # new_from_integer

sub reset
  {
  $_[0] = new_from_integer(0);
  } # reset

sub any_local_actions
  {
  my $self = shift;
  return (
          $self->{_vec}->bit_test(CONGRAT) ||
          $self->{_vec}->bit_test(GOTPAID) ||
          $self->{_vec}->bit_test(SHIPPED) ||
          $self->{_vec}->bit_test(SHIPACK) ||
          $self->{_vec}->bit_test(FEDBACK) ||
          $self->{_vec}->bit_test(EATBACK) ||
          $self->{_vec}->bit_test(ARCHIVE)
         );
  } # any_local_actions

sub as_text
  {
  my $self = shift;
  my $s = '';
  foreach my $sBit (qw( listed ended congratulated paid payment_cleared shipped received left_feedback got_feedback archived ))
    {
    $self->$sBit() and $s .= qq{$sBit, };
    } # foreach
  # Delete comma off the end:
  chop $s; chop $s;
  return $s;
  } # as_text

sub as_integer
  {
  return shift->{_vec}->to_Dec;
  } # as_integer

sub listed
  {
  return shift->_getset(ONLINED, @_);
  } # listed

sub ended
  {
  return shift->_getset(ALLOVER, @_);
  } # ended

sub congratulated
  {
  return shift->_getset(CONGRAT, @_);
  } # congratulated

sub paid
  {
  return shift->_getset(GOTPAID, @_);
  } # paid

sub payment_cleared
  {
  return shift->_getset(CLEARED, @_);
  } # payment_cleared

sub shipped
  {
  return shift->_getset(SHIPPED, @_);
  } # shipped

sub received
  {
  return shift->_getset(SHIPACK, @_);
  } # received

sub left_feedback
  {
  return shift->_getset(FEDBACK, @_);
  } # left_feedback

sub got_feedback
  {
  return shift->_getset(EATBACK, @_);
  } # got_feedback

sub archived
  {
  return shift->_getset(ARCHIVE, @_);
  } # archived

sub _getset
  {
  my $self = shift;
  my ($bit, $arg) = @_;
  if (defined $arg)
    {
    if ($arg)
      {
      $self->{_vec}->Bit_On($bit);
      }
    else
      {
      $self->{_vec}->Bit_Off($bit);
      }
    } # if
  return $self->{_vec}->bit_test($bit);
  } # _getset

1;

__END__