line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package WWW::Myki::Transaction; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
12
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
234
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ATTR = qw(credit zone time date service debit balance desc type); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
14
|
0
|
|
|
|
|
|
my $self = {}; |
15
|
0
|
|
|
|
|
|
bless $self, $class; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
foreach my $attr ( @ATTR ) { |
18
|
0
|
0
|
|
|
|
|
$args{$attr} ? $self->{$attr} = $args{$attr} : croak "Mandatory attribute $attr not present"; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
return $self |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
foreach my $attr (@ATTR) { |
25
|
|
|
|
|
|
|
{ |
26
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
117
|
|
27
|
0
|
|
|
0
|
|
|
*{ __PACKAGE__ .'::'. $attr } = sub { return $_[0]->{$attr} } |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
WWW::Myki::Transaction - Class for operations with a Myki transaction |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 VERSION 0.01 |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Print the date, time, service, description and cost of our last 15 transactions |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
foreach my $trip ( $card->transactions ) { |
42
|
|
|
|
|
|
|
printf( "%10s %8s %-10s %-20s %-5s\n", |
43
|
|
|
|
|
|
|
$trip->date, |
44
|
|
|
|
|
|
|
$trip->time, |
45
|
|
|
|
|
|
|
$trip->service, |
46
|
|
|
|
|
|
|
$trip->desc, |
47
|
|
|
|
|
|
|
$trip->debit ) |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Maybe do a rough calculation of the cost of public transport per day |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
use List::Util qw( sum ); |
53
|
|
|
|
|
|
|
my %sum; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
foreach my $t ( $card->transactions ) { |
56
|
|
|
|
|
|
|
( my $cost = $t->debit ) =~ s/(-|\$|\s)//g; |
57
|
|
|
|
|
|
|
$sum{ $t->date } += $cost; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
print "Average daily cost of travel on public transport: " |
61
|
|
|
|
|
|
|
. ( ( sum values %sum ) / ( keys %sum ) ) . "\n"; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Still cheaper than the environmental cost of driving to work |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
L is a class providing Myki transaction querying functionality for registered Myki users. |
68
|
|
|
|
|
|
|
Each WWW::Myki::Transaction object is representative of a single Myki card transaction. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Please note that you're are not meant to call the constructor yourself, instead a WWW::Myki::Transaction |
71
|
|
|
|
|
|
|
object will be created automatically for you by calls to methods in a L object like |
72
|
|
|
|
|
|
|
B. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 METHODS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 date |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Return the date of the transaction using the format DD/MM/YYYY. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 time |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Print the time of the last transaction using the format HH:MM:SS AM/PM. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 service |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The type of service for the last transaction (e.g. busi or train) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 zone |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
The transit zone for the last transaction. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 desc |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
A description of the transaction usually including the start and destination localities and a service name. |
95
|
|
|
|
|
|
|
This may be a hyphen (-) where no information is provided. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 debit |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The amount debited for the transaction using in decimal currency format (i.e. $D.DD) where present, or a hyphen |
100
|
|
|
|
|
|
|
where no debit was made. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 credit |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The amount credited for the transaction using in decimal currency format (i.e. $D.DD) where present, or a hyphen |
105
|
|
|
|
|
|
|
where no credit was made. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 balance |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
The balance of the associated Myki card at the time this transaction was completed in decimal curreny format. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 type |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
The type of transaction made (e.g. Touch-on or Touch-off). |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Luke Poskitt, C<< >> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 BUGS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through the web interface |
122
|
|
|
|
|
|
|
at L. I will be notified, and then you'll |
123
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SUPPORT |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
perldoc WWW::Myki::Transaction |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
You can also look for information at: |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=over 4 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * CPAN Ratings |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * Search CPAN |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Copyright 2012 Luke Poskitt. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
158
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
159
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SEE ALSO |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
L, L |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |