| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Business::CreditCard::Object; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '1.00'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
548
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
27
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
851
|
use Business::CreditCard (); |
|
|
1
|
|
|
|
|
1731
|
|
|
|
1
|
|
|
|
|
42
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use overload |
|
11
|
30
|
|
|
30
|
|
439
|
'""' => sub { shift->number }, |
|
12
|
1
|
|
|
1
|
|
1873
|
fallback => 1; |
|
|
1
|
|
|
|
|
1330
|
|
|
|
1
|
|
|
|
|
15
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Business::CreditCard::Object - a Credit Card object |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $card = Business::CreditCard::Object->new("4929-4929-4929-4929"); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
if ($card->is_valid) { |
|
23
|
|
|
|
|
|
|
print "Card " . $card->number . " is a " . $card->type; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This provides an OO interface around the Business::CreditCard module. |
|
29
|
|
|
|
|
|
|
You instantiate it with a card number, and can ask if it is valid, for |
|
30
|
|
|
|
|
|
|
a standardised version of the card number, and what type of card it is. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 new |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $card = Business::CreditCard::Object->new("4929-4929-4929-4929"); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Construct a new Card object. The card number can contain optional |
|
39
|
|
|
|
|
|
|
numbers and/or spaces. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 is_valid |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This computes the checksum for the card given and returns a boolean |
|
44
|
|
|
|
|
|
|
value for whether or not the number passes this check. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 type |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This returns the type of card given. See L for a |
|
49
|
|
|
|
|
|
|
list of possible values. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 number |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This returns a standardised version of the card number as a string of |
|
54
|
|
|
|
|
|
|
digits with all spaces and minus signs removed. The object will also |
|
55
|
|
|
|
|
|
|
stringify to this value. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new { |
|
60
|
6
|
|
|
6
|
1
|
2408
|
my ($class, $no) = @_; |
|
61
|
6
|
|
|
|
|
28
|
bless { |
|
62
|
|
|
|
|
|
|
_no => $no, |
|
63
|
|
|
|
|
|
|
} => $class; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub number { |
|
67
|
56
|
|
|
56
|
1
|
72
|
my $self = shift; |
|
68
|
56
|
|
66
|
|
|
381
|
$self->{number} ||= do { |
|
69
|
6
|
|
|
|
|
37
|
(my $no = $self->{_no}) =~ s/[-\s]//g; |
|
70
|
6
|
|
|
|
|
36
|
$no; |
|
71
|
|
|
|
|
|
|
}; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub is_valid { |
|
75
|
6
|
|
|
6
|
1
|
33
|
Business::CreditCard::validate(shift->number) |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub type { |
|
79
|
5
|
|
|
5
|
1
|
13
|
Business::CreditCard::cardtype(shift->number) |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHOR |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Tony Bowden |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 BUGS and QUERIES |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Please direct all correspondence regarding this module to: |
|
89
|
|
|
|
|
|
|
bug-Business-CreditCard-Object@rt.cpan.org |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Business::CreditCard |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Copyright (C) 2004-2005 Tony Bowden. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
|
100
|
|
|
|
|
|
|
the terms of the GNU General Public License; either version 2 of the License, |
|
101
|
|
|
|
|
|
|
or (at your option) any later version. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT |
|
104
|
|
|
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
105
|
|
|
|
|
|
|
FOR A PARTICULAR PURPOSE. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
|
108
|
|
|
|
|
|
|
|