| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | # $rcs = ' $Id: Status.pm,v 1.17 2010-03-06 13:33:22 Martin Exp $ ' ; | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | package WWW::Ebay::Status; | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 5 |  |  | 5 |  | 20333 | use strict; | 
|  | 5 |  |  |  |  | 7 |  | 
|  | 5 |  |  |  |  | 114 |  | 
| 7 | 5 |  |  | 5 |  | 18 | use warnings; | 
|  | 5 |  |  |  |  | 5 |  | 
|  | 5 |  |  |  |  | 284 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 NAME | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | WWW::Ebay::Status -- encapsulate auction status | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | use WWW::Ebay::Status; | 
| 16 |  |  |  |  |  |  | my $oStatus = new WWW::Ebay::Status; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | A convenience class for keeping track of the status of one auction, | 
| 21 |  |  |  |  |  |  | such as an auction you are selling on www.ebay.com | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | The status of an auction consists of several yes/no flags. | 
| 24 |  |  |  |  |  |  | Each yes/no flag indicates whether a certain operation has been performed on this auction. | 
| 25 |  |  |  |  |  |  | The available flags are described below under FLAGS. | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =head1 BUGS | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | Please tell the author if you find any. | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | =head1 METHODS | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | =over | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =cut | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | my | 
| 38 |  |  |  |  |  |  | $VERSION = do { my @r = (q$Revision: 1.17 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | # We use a bitvector for simplicity, even though many of the states | 
| 41 |  |  |  |  |  |  | # are mutually exclusive. | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 5 |  |  | 5 |  | 1080 | use Bit::Vector; | 
|  | 5 |  |  |  |  | 2212 |  | 
|  | 5 |  |  |  |  | 194 |  | 
| 44 | 5 |  |  | 5 |  | 18 | use Carp qw( carp cluck ); | 
|  | 5 |  |  |  |  | 5 |  | 
|  | 5 |  |  |  |  | 199 |  | 
| 45 | 5 |  |  | 5 |  | 1561 | use Data::Dumper; # for debugging only | 
|  | 5 |  |  |  |  | 18779 |  | 
|  | 5 |  |  |  |  | 241 |  | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | # These constants return the bit position of the yes/no value: | 
| 48 | 5 |  |  | 5 |  | 21 | use constant ONLINED => 0;  # Have we posted the auction, or is it in | 
|  | 5 |  |  |  |  | 4 |  | 
|  | 5 |  |  |  |  | 276 |  | 
| 49 |  |  |  |  |  |  | # the "outbox"? | 
| 50 | 5 |  |  | 5 |  | 15 | use constant ALLOVER => 1;  # Has the auction ended, or still in progress? | 
|  | 5 |  |  |  |  | 19 |  | 
|  | 5 |  |  |  |  | 187 |  | 
| 51 | 5 |  |  | 5 |  | 16 | use constant CONGRAT => 2;  # Have we sent congrats email to the buyer? | 
|  | 5 |  |  |  |  | 5 |  | 
|  | 5 |  |  |  |  | 186 |  | 
| 52 | 5 |  |  | 5 |  | 16 | use constant GOTPAID => 3;  # Have we received payment? | 
|  | 5 |  |  |  |  | 10 |  | 
|  | 5 |  |  |  |  | 165 |  | 
| 53 | 5 |  |  | 5 |  | 20 | use constant CLEARED => 4;  # Has the check cleared? | 
|  | 5 |  |  |  |  | 5 |  | 
|  | 5 |  |  |  |  | 150 |  | 
| 54 | 5 |  |  | 5 |  | 15 | use constant SHIPPED => 5;  # Have we shipped the item? | 
|  | 5 |  |  |  |  | 5 |  | 
|  | 5 |  |  |  |  | 155 |  | 
| 55 | 5 |  |  | 5 |  | 11 | use constant SHIPACK => 6;  # Has buyer informed us that item was received? | 
|  | 5 |  |  |  |  | 5 |  | 
|  | 5 |  |  |  |  | 200 |  | 
| 56 | 5 |  |  | 5 |  | 16 | use constant FEDBACK => 7;  # Have we sent feedback to buyer?  Outbox == sent | 
|  | 5 |  |  |  |  | 5 |  | 
|  | 5 |  |  |  |  | 149 |  | 
| 57 | 5 |  |  | 5 |  | 15 | use constant EATBACK => 8;  # Has the buyer left feedback for us? | 
|  | 5 |  |  |  |  | 5 |  | 
|  | 5 |  |  |  |  | 160 |  | 
| 58 | 5 |  |  | 5 |  | 15 | use constant ARCHIVE => 30;  # This is a huge number because it's | 
|  | 5 |  |  |  |  | 22 |  | 
|  | 5 |  |  |  |  | 2701 |  | 
| 59 |  |  |  |  |  |  | # pretty much the last thing anybody can | 
| 60 |  |  |  |  |  |  | # ever do with an auction | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | my $iNumBits = 32; | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | =item new | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | Creates and returns a new Status object. | 
| 67 |  |  |  |  |  |  | All status flags are 'off'. | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =cut | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | sub new | 
| 72 |  |  |  |  |  |  | { | 
| 73 | 23 |  |  | 23 | 1 | 2298 | my $proto = shift; | 
| 74 | 23 |  | 100 |  |  | 70 | my $class = ref($proto) || $proto; | 
| 75 | 23 | 100 |  |  |  | 35 | unless ($class) | 
| 76 |  |  |  |  |  |  | { | 
| 77 | 1 |  |  |  |  | 165 | carp "You can not call new like that"; | 
| 78 | 1 |  |  |  |  | 8 | $class = 'FAIL'; | 
| 79 |  |  |  |  |  |  | } # unless | 
| 80 | 23 |  |  |  |  | 103 | my $oVector = new Bit::Vector($iNumBits); | 
| 81 | 23 |  |  |  |  | 37 | my $self  = { | 
| 82 |  |  |  |  |  |  | _vec => $oVector, | 
| 83 |  |  |  |  |  |  | }; | 
| 84 | 23 |  |  |  |  | 56 | return bless ($self, $class); | 
| 85 |  |  |  |  |  |  | } # new | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =item new_from_integer | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | Creates and returns a new Status object, | 
| 90 |  |  |  |  |  |  | with all values derived from the given integer. | 
| 91 |  |  |  |  |  |  | (Most likely, the integer was obtained by calling as_integer() on another WWW::Ebay::Status object.) | 
| 92 |  |  |  |  |  |  | Useful as a Thaw method. | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | =cut | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | sub new_from_integer | 
| 97 |  |  |  |  |  |  | { | 
| 98 |  |  |  |  |  |  | # die sprintf(" + this is %s::new_from_integer(@_)\n", __PACKAGE__); | 
| 99 | 16 |  |  | 16 | 1 | 719 | my $arg = shift; | 
| 100 |  |  |  |  |  |  | # If this was called as a method, the integer is the second | 
| 101 |  |  |  |  |  |  | # argument: | 
| 102 | 16 | 100 | 100 |  |  | 87 | $arg = shift if ( | 
| 103 |  |  |  |  |  |  | # This lets them call it as new_from_integer WWW::Ebay::Status(0): | 
| 104 |  |  |  |  |  |  | # Or as WWW::Ebay::Status::new_from_integer(0): | 
| 105 |  |  |  |  |  |  | ($arg eq __PACKAGE__) | 
| 106 |  |  |  |  |  |  | || | 
| 107 |  |  |  |  |  |  | # This lets them call it as $o->new_from_integer(0): | 
| 108 |  |  |  |  |  |  | (ref($arg) eq __PACKAGE__) | 
| 109 |  |  |  |  |  |  | ); | 
| 110 |  |  |  |  |  |  | # If arg is missing or undef, use zero: | 
| 111 | 16 |  | 100 |  |  | 41 | $arg ||= 0; | 
| 112 |  |  |  |  |  |  | # Create a new object: | 
| 113 | 16 |  |  |  |  | 46 | my $self = &new(__PACKAGE__); | 
| 114 |  |  |  |  |  |  | # No error-checking here; ASSume that $arg is something that | 
| 115 |  |  |  |  |  |  | # Bit::Vector sees as a decimal integer: | 
| 116 | 16 |  |  |  |  | 74 | $self->{_vec}->from_Dec($arg); | 
| 117 | 16 |  |  |  |  | 31 | return $self; | 
| 118 |  |  |  |  |  |  | } # new_from_integer | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =item reset | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | Set all flags to false. | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | =cut | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | sub reset | 
| 127 |  |  |  |  |  |  | { | 
| 128 | 11 |  |  | 11 | 1 | 394 | $_[0] = new_from_integer(0); | 
| 129 |  |  |  |  |  |  | } # reset | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | =item any_local_actions | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | Consider that this Status object refers to auction X.  This method | 
| 134 |  |  |  |  |  |  | returns true if any operations have been performed on auction X after | 
| 135 |  |  |  |  |  |  | it has ended. | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =cut | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | sub any_local_actions | 
| 140 |  |  |  |  |  |  | { | 
| 141 | 8 |  |  | 8 | 1 | 6 | my $self = shift; | 
| 142 |  |  |  |  |  |  | return ( | 
| 143 |  |  |  |  |  |  | $self->{_vec}->bit_test(CONGRAT) || | 
| 144 |  |  |  |  |  |  | $self->{_vec}->bit_test(GOTPAID) || | 
| 145 |  |  |  |  |  |  | $self->{_vec}->bit_test(SHIPPED) || | 
| 146 |  |  |  |  |  |  | $self->{_vec}->bit_test(SHIPACK) || | 
| 147 |  |  |  |  |  |  | $self->{_vec}->bit_test(FEDBACK) || | 
| 148 |  |  |  |  |  |  | $self->{_vec}->bit_test(EATBACK) || | 
| 149 | 8 |  | 100 |  |  | 95 | $self->{_vec}->bit_test(ARCHIVE) | 
| 150 |  |  |  |  |  |  | ); | 
| 151 |  |  |  |  |  |  | } # any_local_actions | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =item as_text | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | Returns a human-readable description of all the set flags. | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | =cut | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | sub as_text | 
| 160 |  |  |  |  |  |  | { | 
| 161 | 1 |  |  | 1 | 1 | 2 | my $self = shift; | 
| 162 | 1 |  |  |  |  | 1 | my $s = ''; | 
| 163 | 1 |  |  |  |  | 3 | foreach my $sBit (qw( listed ended congratulated paid payment_cleared shipped received left_feedback got_feedback archived )) | 
| 164 |  |  |  |  |  |  | { | 
| 165 | 10 | 100 |  |  |  | 16 | $self->$sBit() and $s .= qq{$sBit, }; | 
| 166 |  |  |  |  |  |  | } # foreach | 
| 167 |  |  |  |  |  |  | # Delete comma off the end: | 
| 168 | 1 |  |  |  |  | 2 | chop $s; chop $s; | 
|  | 1 |  |  |  |  | 2 |  | 
| 169 | 1 |  |  |  |  | 2 | return $s; | 
| 170 |  |  |  |  |  |  | } # as_text | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | =item as_integer | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | Returns an integer representation of the status bits. | 
| 175 |  |  |  |  |  |  | Useful as a Freeze method. | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =cut | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | sub as_integer | 
| 180 |  |  |  |  |  |  | { | 
| 181 | 3 |  |  | 3 | 1 | 343 | return shift->{_vec}->to_Dec; | 
| 182 |  |  |  |  |  |  | } # as_integer | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  | =back | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | =head1 FLAGS | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  | These are the yes/no flags that apply to an auction. | 
| 189 |  |  |  |  |  |  | They all act as get/set methods: | 
| 190 |  |  |  |  |  |  | give an argument to set the value; | 
| 191 |  |  |  |  |  |  | give no arguments to get the value. | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | =over | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | =cut | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | =item listed | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | I.e. this auction has been uploaded to eBay and is underway. | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | =cut | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | sub listed | 
| 204 |  |  |  |  |  |  | { | 
| 205 | 12 |  |  | 12 | 1 | 2325 | return shift->_getset(ONLINED, @_); | 
| 206 |  |  |  |  |  |  | } # listed | 
| 207 |  |  |  |  |  |  |  | 
| 208 |  |  |  |  |  |  | =item ended | 
| 209 |  |  |  |  |  |  |  | 
| 210 |  |  |  |  |  |  | I.e. bidding is closed. | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | =cut | 
| 213 |  |  |  |  |  |  |  | 
| 214 |  |  |  |  |  |  | sub ended | 
| 215 |  |  |  |  |  |  | { | 
| 216 | 12 |  |  | 12 | 1 | 909 | return shift->_getset(ALLOVER, @_); | 
| 217 |  |  |  |  |  |  | } # ended | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  | =item congratulated | 
| 220 |  |  |  |  |  |  |  | 
| 221 |  |  |  |  |  |  | I.e. we have sent a "Congratulations, please pay me now" email. | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | =cut | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  | sub congratulated | 
| 226 |  |  |  |  |  |  | { | 
| 227 | 13 |  |  | 13 | 1 | 1253 | return shift->_getset(CONGRAT, @_); | 
| 228 |  |  |  |  |  |  | } # congratulated | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  | =item paid | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | =cut | 
| 233 |  |  |  |  |  |  |  | 
| 234 |  |  |  |  |  |  | sub paid | 
| 235 |  |  |  |  |  |  | { | 
| 236 | 14 |  |  | 14 | 1 | 1322 | return shift->_getset(GOTPAID, @_); | 
| 237 |  |  |  |  |  |  | } # paid | 
| 238 |  |  |  |  |  |  |  | 
| 239 |  |  |  |  |  |  | =item payment_cleared | 
| 240 |  |  |  |  |  |  |  | 
| 241 |  |  |  |  |  |  | =cut | 
| 242 |  |  |  |  |  |  |  | 
| 243 |  |  |  |  |  |  | sub payment_cleared | 
| 244 |  |  |  |  |  |  | { | 
| 245 | 11 |  |  | 11 | 1 | 1273 | return shift->_getset(CLEARED, @_); | 
| 246 |  |  |  |  |  |  | } # payment_cleared | 
| 247 |  |  |  |  |  |  |  | 
| 248 |  |  |  |  |  |  | =item shipped | 
| 249 |  |  |  |  |  |  |  | 
| 250 |  |  |  |  |  |  | =cut | 
| 251 |  |  |  |  |  |  |  | 
| 252 |  |  |  |  |  |  | sub shipped | 
| 253 |  |  |  |  |  |  | { | 
| 254 | 13 |  |  | 13 | 1 | 1277 | return shift->_getset(SHIPPED, @_); | 
| 255 |  |  |  |  |  |  | } # shipped | 
| 256 |  |  |  |  |  |  |  | 
| 257 |  |  |  |  |  |  | =item received | 
| 258 |  |  |  |  |  |  |  | 
| 259 |  |  |  |  |  |  | =cut | 
| 260 |  |  |  |  |  |  |  | 
| 261 |  |  |  |  |  |  | sub received | 
| 262 |  |  |  |  |  |  | { | 
| 263 | 12 |  |  | 12 | 1 | 1354 | return shift->_getset(SHIPACK, @_); | 
| 264 |  |  |  |  |  |  | } # received | 
| 265 |  |  |  |  |  |  |  | 
| 266 |  |  |  |  |  |  | =item left_feedback | 
| 267 |  |  |  |  |  |  |  | 
| 268 |  |  |  |  |  |  | =cut | 
| 269 |  |  |  |  |  |  |  | 
| 270 |  |  |  |  |  |  | sub left_feedback | 
| 271 |  |  |  |  |  |  | { | 
| 272 | 12 |  |  | 12 | 1 | 1238 | return shift->_getset(FEDBACK, @_); | 
| 273 |  |  |  |  |  |  | } # left_feedback | 
| 274 |  |  |  |  |  |  |  | 
| 275 |  |  |  |  |  |  | =item got_feedback | 
| 276 |  |  |  |  |  |  |  | 
| 277 |  |  |  |  |  |  | =cut | 
| 278 |  |  |  |  |  |  |  | 
| 279 |  |  |  |  |  |  | sub got_feedback | 
| 280 |  |  |  |  |  |  | { | 
| 281 | 12 |  |  | 12 | 1 | 1281 | return shift->_getset(EATBACK, @_); | 
| 282 |  |  |  |  |  |  | } # got_feedback | 
| 283 |  |  |  |  |  |  |  | 
| 284 |  |  |  |  |  |  | =item archived | 
| 285 |  |  |  |  |  |  |  | 
| 286 |  |  |  |  |  |  | E.g. all actions are done, don't show this auction any more. | 
| 287 |  |  |  |  |  |  |  | 
| 288 |  |  |  |  |  |  | =cut | 
| 289 |  |  |  |  |  |  |  | 
| 290 |  |  |  |  |  |  | sub archived | 
| 291 |  |  |  |  |  |  | { | 
| 292 | 8 |  |  | 8 | 1 | 1289 | return shift->_getset(ARCHIVE, @_); | 
| 293 |  |  |  |  |  |  | } # archived | 
| 294 |  |  |  |  |  |  |  | 
| 295 |  |  |  |  |  |  | =back | 
| 296 |  |  |  |  |  |  |  | 
| 297 |  |  |  |  |  |  | =cut | 
| 298 |  |  |  |  |  |  |  | 
| 299 |  |  |  |  |  |  | sub _getset | 
| 300 |  |  |  |  |  |  | { | 
| 301 | 119 |  |  | 119 |  | 100 | my $self = shift; | 
| 302 | 119 |  |  |  |  | 105 | my ($bit, $arg) = @_; | 
| 303 | 119 | 100 |  |  |  | 193 | if (defined $arg) | 
| 304 |  |  |  |  |  |  | { | 
| 305 | 33 | 100 |  |  |  | 37 | if ($arg) | 
| 306 |  |  |  |  |  |  | { | 
| 307 | 26 |  |  |  |  | 48 | $self->{_vec}->Bit_On($bit); | 
| 308 |  |  |  |  |  |  | } | 
| 309 |  |  |  |  |  |  | else | 
| 310 |  |  |  |  |  |  | { | 
| 311 | 7 |  |  |  |  | 23 | $self->{_vec}->Bit_Off($bit); | 
| 312 |  |  |  |  |  |  | } | 
| 313 |  |  |  |  |  |  | } # if | 
| 314 | 119 |  |  |  |  | 419 | return $self->{_vec}->bit_test($bit); | 
| 315 |  |  |  |  |  |  | } # _getset | 
| 316 |  |  |  |  |  |  |  | 
| 317 |  |  |  |  |  |  | =head1 AUTHOR | 
| 318 |  |  |  |  |  |  |  | 
| 319 |  |  |  |  |  |  | Martin 'Kingpin' Thurn, C, L. | 
| 320 |  |  |  |  |  |  |  | 
| 321 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 322 |  |  |  |  |  |  |  | 
| 323 |  |  |  |  |  |  | Copyright (C) 2001-2007 Martin Thurn | 
| 324 |  |  |  |  |  |  | All Rights Reserved | 
| 325 |  |  |  |  |  |  |  | 
| 326 |  |  |  |  |  |  | =cut | 
| 327 |  |  |  |  |  |  |  | 
| 328 |  |  |  |  |  |  | 1; | 
| 329 |  |  |  |  |  |  |  | 
| 330 |  |  |  |  |  |  | __END__ |