| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | # $rcs = ' $Id: Customer.pm,v 1.16 2010-05-08 12:50:29 Martin Exp $ ' ; | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | Copyright (C) 2001 Martin Thurn | 
| 7 |  |  |  |  |  |  | All Rights Reserved | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 NAME | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | WWW::Ebay::Customer - information about an auction customer | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | use WWW::Ebay::Customer; | 
| 16 |  |  |  |  |  |  | my $oCustomer = new WWW::Ebay::Customer; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | An object that encapsulates information about an auction customer. | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =head1 OPTIONS | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | Object (hash) values and editor (GUI) widgets | 
| 25 |  |  |  |  |  |  | correspond to pieces of information needed to identify a | 
| 26 |  |  |  |  |  |  | buyer or seller of a (successful) auction. | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =head1 METHODS | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =cut | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | package WWW::Ebay::Customer; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 2 |  |  | 2 |  | 19761 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 56 |  | 
| 35 | 2 |  |  | 2 |  | 7 | use warnings; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 44 |  | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | require 5; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 2 |  |  | 2 |  | 6 | use Carp; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 82 |  | 
| 40 | 2 |  |  | 2 |  | 567 | use Data::Dumper;  # for debugging only | 
|  | 2 |  |  |  |  | 6514 |  | 
|  | 2 |  |  |  |  | 85 |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 2 |  |  | 2 |  | 8 | use vars qw( $AUTOLOAD $VERSION ); | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 142 |  | 
| 43 |  |  |  |  |  |  | $VERSION = do { my @r = (q$Revision: 1.16 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 2 |  |  | 2 |  | 8 | use constant DEBUG_NEW => 0; | 
|  | 2 |  |  |  |  | 1 |  | 
|  | 2 |  |  |  |  | 977 |  | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | my %hsPermitted = ( | 
| 48 |  |  |  |  |  |  | 'ebayid' => '', | 
| 49 |  |  |  |  |  |  | 'email' => '', | 
| 50 |  |  |  |  |  |  | 'paypalid' => '', | 
| 51 |  |  |  |  |  |  | 'name' => '', | 
| 52 |  |  |  |  |  |  | 'address1' => '', | 
| 53 |  |  |  |  |  |  | 'address2' => '', | 
| 54 |  |  |  |  |  |  | 'address3' => '', | 
| 55 |  |  |  |  |  |  | ); | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | =head2 new | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | Create a new object of this type. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =cut | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | sub new | 
| 64 |  |  |  |  |  |  | { | 
| 65 | 5 |  |  | 5 | 1 | 662 | my $proto = shift; | 
| 66 | 5 |  | 50 |  |  | 21 | my $rh = shift || {}; | 
| 67 | 5 |  |  |  |  | 6 | print STDERR " + this is new Customer, arg is ", Dumper($rh) if DEBUG_NEW; | 
| 68 | 5 |  | 100 |  |  | 15 | my $class = ref($proto) || $proto; | 
| 69 | 5 | 100 |  |  |  | 8 | unless ($class) | 
| 70 |  |  |  |  |  |  | { | 
| 71 | 1 |  |  |  |  | 89 | carp "You can not call new like that"; | 
| 72 |  |  |  |  |  |  | # Keep going, but don't give the caller what they're expecting: | 
| 73 | 1 |  |  |  |  | 15 | return bless({}, 'FAIL'); | 
| 74 |  |  |  |  |  |  | } # unless | 
| 75 | 4 |  |  |  |  | 18 | my $self = { | 
| 76 |  |  |  |  |  |  | %hsPermitted, | 
| 77 |  |  |  |  |  |  | }; | 
| 78 |  |  |  |  |  |  | # Make a COPY of the remaining arguments: | 
| 79 | 4 |  |  |  |  | 14 | while (my ($key,$val) = each %$rh) | 
| 80 |  |  |  |  |  |  | { | 
| 81 | 0 |  |  |  |  | 0 | $self->{$key} = $val; | 
| 82 |  |  |  |  |  |  | } # while | 
| 83 | 4 |  |  |  |  | 4 | bless ($self, $class); | 
| 84 | 4 |  |  |  |  | 4 | print STDERR " + new Customer is ", Dumper($self) if DEBUG_NEW; | 
| 85 | 4 |  |  |  |  | 8 | return $self; | 
| 86 |  |  |  |  |  |  | } # new | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | sub _elem | 
| 89 |  |  |  |  |  |  | { | 
| 90 | 56 |  |  | 56 |  | 46 | my $self = shift; | 
| 91 | 56 |  |  |  |  | 46 | my $elem = shift; | 
| 92 | 56 |  |  |  |  | 48 | my $ret = $self->{$elem}; | 
| 93 | 56 | 100 |  |  |  | 78 | if (@_) | 
| 94 |  |  |  |  |  |  | { | 
| 95 | 21 |  |  |  |  | 21 | $self->{$elem} = shift; | 
| 96 |  |  |  |  |  |  | } # if | 
| 97 | 56 |  |  |  |  | 136 | return $ret; | 
| 98 |  |  |  |  |  |  | } # _elem | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | sub AUTOLOAD | 
| 102 |  |  |  |  |  |  | { | 
| 103 |  |  |  |  |  |  | # print STDERR " + this is ::Single::AUTOLOAD($AUTOLOAD,@_)\n"; | 
| 104 | 57 |  |  | 57 |  | 794 | $AUTOLOAD =~ s/.*:://; | 
| 105 | 57 | 100 |  |  |  | 108 | unless (exists $hsPermitted{$AUTOLOAD}) | 
| 106 |  |  |  |  |  |  | { | 
| 107 | 1 |  |  |  |  | 140 | carp " --- element '$AUTOLOAD' is not allowed"; | 
| 108 | 1 |  |  |  |  | 42 | return undef; | 
| 109 |  |  |  |  |  |  | } # unless | 
| 110 | 56 |  |  |  |  | 84 | shift->_elem($AUTOLOAD, @_); | 
| 111 |  |  |  |  |  |  | } # AUTOLOAD | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | # define this so AUTOLOAD does not try to handle it: | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | sub DESTROY | 
| 117 |  |  |  | 0 |  |  | { | 
| 118 |  |  |  |  |  |  | } # DESTROY | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =head2 editor | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | Creates a Tk widget for editing a customer's information. | 
| 124 |  |  |  |  |  |  | Takes one argument, an existing Tk widget into which the editor | 
| 125 |  |  |  |  |  |  | widget will be packed.  Should be a Frame or MainWindow or similar. | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =cut | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | sub editor | 
| 130 |  |  |  |  |  |  | { | 
| 131 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 132 |  |  |  |  |  |  | # Takes one argument, a Tk Widget (that can have items packed into it). | 
| 133 | 0 |  |  |  |  | 0 | my $w = shift; | 
| 134 |  |  |  |  |  |  | # Create some shortcuts: | 
| 135 | 0 |  |  |  |  | 0 | my @asAllPack = qw( -pady 3 ); | 
| 136 | 0 |  |  |  |  | 0 | my @asHeadPack = (@asAllPack, qw( -column 0 -sticky e )); | 
| 137 | 0 |  |  |  |  | 0 | my @asDataPack = (@asAllPack, qw( -column 1 -sticky w )); | 
| 138 |  |  |  |  |  |  | # Add a Frame, in case $w is not using the grid manager: | 
| 139 | 0 |  |  |  |  | 0 | my $f1 = $w->Frame( | 
| 140 |  |  |  |  |  |  | )->pack(qw( -side top -fill x -padx 4 -pady 4 )); | 
| 141 |  |  |  |  |  |  | # Pack it up: | 
| 142 | 0 |  |  |  |  | 0 | $f1->Label( | 
| 143 |  |  |  |  |  |  | -text => 'eBay ID: ', | 
| 144 |  |  |  |  |  |  | )->grid(@asHeadPack, qw( -row 0 )); | 
| 145 |  |  |  |  |  |  | $f1->Entry( | 
| 146 |  |  |  |  |  |  | -textvariable => \$self->{ebayid}, | 
| 147 | 0 |  |  |  |  | 0 | -width => 35, | 
| 148 |  |  |  |  |  |  | # This is the key, do not let them change it: | 
| 149 |  |  |  |  |  |  | -state => 'disabled', | 
| 150 |  |  |  |  |  |  | )->grid(@asDataPack, qw( -row 0 )); | 
| 151 | 0 |  |  |  |  | 0 | $f1->Label( | 
| 152 |  |  |  |  |  |  | -text => 'email address: ', | 
| 153 |  |  |  |  |  |  | )->grid(@asHeadPack, qw( -row 1 )); | 
| 154 |  |  |  |  |  |  | $f1->Entry( | 
| 155 |  |  |  |  |  |  | -textvariable => \$self->{email}, | 
| 156 | 0 |  |  |  |  | 0 | -width => 35, | 
| 157 |  |  |  |  |  |  | )->grid(@asDataPack, qw( -row 1 )); | 
| 158 | 0 |  |  |  |  | 0 | $f1->Label( | 
| 159 |  |  |  |  |  |  | -text => 'PayPal ID: ', | 
| 160 |  |  |  |  |  |  | )->grid(@asHeadPack, qw( -row 2 )); | 
| 161 |  |  |  |  |  |  | $f1->Entry( | 
| 162 |  |  |  |  |  |  | -textvariable => \$self->{paypalid}, | 
| 163 | 0 |  |  |  |  | 0 | -width => 35, | 
| 164 |  |  |  |  |  |  | )->grid(@asDataPack, qw( -row 2 )); | 
| 165 | 0 |  |  |  |  | 0 | $f1->Label( | 
| 166 |  |  |  |  |  |  | -text => 'name: ', | 
| 167 |  |  |  |  |  |  | )->grid(@asHeadPack, qw( -row 3 )); | 
| 168 |  |  |  |  |  |  | $f1->Entry( | 
| 169 |  |  |  |  |  |  | -textvariable => \$self->{name}, | 
| 170 | 0 |  |  |  |  | 0 | -width => 35, | 
| 171 |  |  |  |  |  |  | )->grid(@asDataPack, qw( -row 3 )); | 
| 172 | 0 |  |  |  |  | 0 | $f1->Label( | 
| 173 |  |  |  |  |  |  | -text => 'address1: ', | 
| 174 |  |  |  |  |  |  | )->grid(@asHeadPack, qw( -row 4 )); | 
| 175 |  |  |  |  |  |  | $f1->Entry( | 
| 176 |  |  |  |  |  |  | -textvariable => \$self->{address1}, | 
| 177 | 0 |  |  |  |  | 0 | -width => 35, | 
| 178 |  |  |  |  |  |  | )->grid(@asDataPack, qw( -row 4 )); | 
| 179 | 0 |  |  |  |  | 0 | $f1->Label( | 
| 180 |  |  |  |  |  |  | -text => 'address2: ', | 
| 181 |  |  |  |  |  |  | )->grid(@asHeadPack, qw( -row 5 )); | 
| 182 |  |  |  |  |  |  | $f1->Entry( | 
| 183 |  |  |  |  |  |  | -textvariable => \$self->{address2}, | 
| 184 | 0 |  |  |  |  | 0 | -width => 35, | 
| 185 |  |  |  |  |  |  | )->grid(@asDataPack, qw( -row 5 )); | 
| 186 | 0 |  |  |  |  | 0 | $f1->Label( | 
| 187 |  |  |  |  |  |  | -text => 'address3: ', | 
| 188 |  |  |  |  |  |  | )->grid(@asHeadPack, qw( -row 6 )); | 
| 189 |  |  |  |  |  |  | $f1->Entry( | 
| 190 |  |  |  |  |  |  | -textvariable => \$self->{address3}, | 
| 191 | 0 |  |  |  |  | 0 | -width => 35, | 
| 192 |  |  |  |  |  |  | )->grid(@asDataPack, qw( -row 6 )); | 
| 193 |  |  |  |  |  |  | } # editor | 
| 194 |  |  |  |  |  |  |  | 
| 195 | 2 |  |  | 2 |  | 9 | use constant DEBUG_PASTE => 0; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 771 |  | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | =head2 editor_paste | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | Takes one argument, a string. | 
| 200 |  |  |  |  |  |  | Tries to interpret the argument as a name and/or address as follows: | 
| 201 |  |  |  |  |  |  | If the string contains three or more lines, | 
| 202 |  |  |  |  |  |  | put the first line into the name and the remaining lines into the address. | 
| 203 |  |  |  |  |  |  | If the string contains two lines, | 
| 204 |  |  |  |  |  |  | put the two lines into the address. | 
| 205 |  |  |  |  |  |  | Otherwise, do nothing. | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | =cut | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | sub editor_paste | 
| 210 |  |  |  |  |  |  | { | 
| 211 |  |  |  |  |  |  | # Smart paste: | 
| 212 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 213 | 0 |  |  |  |  | 0 | my $sPaste = shift; | 
| 214 |  |  |  |  |  |  | # Delete \r: | 
| 215 | 0 |  |  |  |  | 0 | $sPaste =~ s!\r!!g; | 
| 216 |  |  |  |  |  |  | # Delete "blank" lines: | 
| 217 | 0 |  |  |  |  | 0 | $sPaste =~ s!\n\s*\n!\n!g; | 
| 218 |  |  |  |  |  |  | # Delete leading and trailing whitespace: | 
| 219 | 0 |  |  |  |  | 0 | $sPaste =~ s!\A[\ \s\f\t\n]+!!; | 
| 220 | 0 |  |  |  |  | 0 | $sPaste =~ s![\ \s\f\t\n]+\Z!!; | 
| 221 | 0 |  |  |  |  | 0 | my @asPaste = split(/\n/, $sPaste); | 
| 222 | 0 |  |  |  |  | 0 | chomp @asPaste; | 
| 223 | 0 |  |  |  |  | 0 | my $iNumLines = scalar(@asPaste); | 
| 224 | 0 |  |  |  |  | 0 | print STDERR " +   paste has $iNumLines lines\n" if DEBUG_PASTE; | 
| 225 | 0 |  |  |  |  | 0 | my @asDest; | 
| 226 | 0 | 0 |  |  |  | 0 | if (3 < $iNumLines) | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 227 |  |  |  |  |  |  | { | 
| 228 |  |  |  |  |  |  | # Fill them all! | 
| 229 | 0 |  |  |  |  | 0 | @asDest = qw(name address1 address2 address3); | 
| 230 |  |  |  |  |  |  | } | 
| 231 |  |  |  |  |  |  | elsif (2 < $iNumLines) | 
| 232 |  |  |  |  |  |  | { | 
| 233 |  |  |  |  |  |  | # Assume it's a name and standard U.S. address: | 
| 234 | 0 |  |  |  |  | 0 | @asDest = qw(name address1 address2); | 
| 235 |  |  |  |  |  |  | } | 
| 236 |  |  |  |  |  |  | elsif (1 < $iNumLines) | 
| 237 |  |  |  |  |  |  | { | 
| 238 |  |  |  |  |  |  | # Assume it's a standard U.S. address: | 
| 239 | 0 |  |  |  |  | 0 | @asDest = qw(address1 address2); | 
| 240 |  |  |  |  |  |  | } | 
| 241 |  |  |  |  |  |  | else | 
| 242 |  |  |  |  |  |  | { | 
| 243 |  |  |  |  |  |  | # Only one item, or none, or too many: do nothing: | 
| 244 | 0 |  |  |  |  | 0 | @asDest = (); | 
| 245 |  |  |  |  |  |  | } | 
| 246 | 0 |  |  |  |  | 0 | foreach my $sDest (@asDest) | 
| 247 |  |  |  |  |  |  | { | 
| 248 | 0 |  |  |  |  | 0 | my $sLine = shift @asPaste; | 
| 249 |  |  |  |  |  |  | # Delete leading and trailing whitespace: | 
| 250 | 0 |  |  |  |  | 0 | $sLine =~ s!\A[\ \s\f\t]+!!; | 
| 251 | 0 |  |  |  |  | 0 | $sLine =~ s![\ \s\f\t]+\Z!!; | 
| 252 |  |  |  |  |  |  | # Normalize whitespace: | 
| 253 | 0 |  |  |  |  | 0 | $sLine =~ s![\ \s\f\t]+! !g; | 
| 254 | 0 |  |  |  |  | 0 | $self->$sDest($sLine); | 
| 255 |  |  |  |  |  |  | } # foreach | 
| 256 |  |  |  |  |  |  | } # editor_paste | 
| 257 |  |  |  |  |  |  |  | 
| 258 |  |  |  |  |  |  |  | 
| 259 |  |  |  |  |  |  | =head2 editor_finish | 
| 260 |  |  |  |  |  |  |  | 
| 261 |  |  |  |  |  |  | You should call this method after editing is finished, | 
| 262 |  |  |  |  |  |  | before destroying the Tk widget. | 
| 263 |  |  |  |  |  |  |  | 
| 264 |  |  |  |  |  |  | =cut | 
| 265 |  |  |  |  |  |  |  | 
| 266 |  |  |  |  |  |  | sub editor_finish | 
| 267 |  |  |  |  |  |  | { | 
| 268 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 269 |  |  |  |  |  |  | # Retrieve the volatile items from the GUI: | 
| 270 |  |  |  |  |  |  | } # editor_finish | 
| 271 |  |  |  |  |  |  |  | 
| 272 |  |  |  |  |  |  |  | 
| 273 |  |  |  |  |  |  | =head2 clone | 
| 274 |  |  |  |  |  |  |  | 
| 275 |  |  |  |  |  |  | Make a new Ebay::Customer object identical to ourself, and return it. | 
| 276 |  |  |  |  |  |  |  | 
| 277 |  |  |  |  |  |  | =cut | 
| 278 |  |  |  |  |  |  |  | 
| 279 |  |  |  |  |  |  | sub clone | 
| 280 |  |  |  |  |  |  | { | 
| 281 | 1 |  |  | 1 | 1 | 318 | my $self = shift; | 
| 282 | 1 |  |  |  |  | 5 | my $oC = new __PACKAGE__; | 
| 283 | 1 |  |  |  |  | 3 | $self->copy_to($oC); | 
| 284 | 1 |  |  |  |  | 3 | return $oC; | 
| 285 |  |  |  |  |  |  | } # clone | 
| 286 |  |  |  |  |  |  |  | 
| 287 |  |  |  |  |  |  |  | 
| 288 |  |  |  |  |  |  | =head2 copy_to | 
| 289 |  |  |  |  |  |  |  | 
| 290 |  |  |  |  |  |  | Given another Ebay::Customer object, copy our values into him. | 
| 291 |  |  |  |  |  |  |  | 
| 292 |  |  |  |  |  |  | =cut | 
| 293 |  |  |  |  |  |  |  | 
| 294 |  |  |  |  |  |  | sub copy_to | 
| 295 |  |  |  |  |  |  | { | 
| 296 | 3 |  |  | 3 | 1 | 4 | my $self = shift; | 
| 297 | 3 |  |  |  |  | 3 | my $oC = shift; | 
| 298 | 3 | 100 |  |  |  | 9 | unless (ref($oC) eq __PACKAGE__) | 
| 299 |  |  |  |  |  |  | { | 
| 300 | 1 |  |  |  |  | 70 | carp sprintf(" --- argument on copy_to() is not a %s object", __PACKAGE__); | 
| 301 | 1 |  |  |  |  | 30 | return; | 
| 302 |  |  |  |  |  |  | } # unless | 
| 303 | 2 |  |  |  |  | 6 | foreach my $key (keys %hsPermitted) | 
| 304 |  |  |  |  |  |  | { | 
| 305 | 14 |  |  |  |  | 39 | $oC->$key($self->$key()); | 
| 306 |  |  |  |  |  |  | } # foreach | 
| 307 |  |  |  |  |  |  | } # copy_to | 
| 308 |  |  |  |  |  |  |  | 
| 309 |  |  |  |  |  |  |  | 
| 310 |  |  |  |  |  |  | 1; | 
| 311 |  |  |  |  |  |  |  | 
| 312 |  |  |  |  |  |  | =head1 AUTHOR | 
| 313 |  |  |  |  |  |  |  | 
| 314 |  |  |  |  |  |  | Martin 'Kingpin' Thurn, C, L. | 
| 315 |  |  |  |  |  |  |  | 
| 316 |  |  |  |  |  |  | =cut | 
| 317 |  |  |  |  |  |  |  | 
| 318 |  |  |  |  |  |  | __END__ |