blib/lib/Business/Billing/TMobile/UK.pm

filter: Statementstmt 77.7% 42 / 54 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod 100% 2 / 2 totaltotal 76.3% 55 / 72 CC 5 SCAR 6.6
CC
5
Cov
76%
new
3.0
_parse_allowances
3.0
get_allowances
2.0
CRAP 1.9
↑ Summary
1 =head1 MODULE FOR SALE
2  
3 I am not planning to make any changes to this module as I have not been a
4 customer of TMobile for over a year. If someone would like to take over
5 maintenance/development of this module please get in touch.
6  
7 =head1 ANTI-TMOBILE RANT
8  
9 TMobile's lax fraud prevention procedures allowed a random person in a random
10 part of the UK to buy a mobile phone contract at my parents address. TMobile
11 then started to demand money from my parents and ignored initial attempts to
12 explain that the person has a different name from the residents and has never
13 lived at their address. TMobile eventually, after much chasing, agreed to stop
14 demanding money that my family did not owe them, but they to date have not
15 properly apologied for their actions or explained how on earth this person was
16 able to setup the phone contract in the first place.
17  
18 I encourage people not to use T-Mobile.
19  
20 =head1 NAME
21  
22 Business::Billing::TMobile::UK - The fantastic new Business::Billing::TMobile::UK!
23  
24 =head1 SYNOPSIS
25  
26 use Business::Billing::TMobile::UK
27  
28 =head1 DESCRIPTION
29  
30 An interface to TMobile UK's website for getting allowance and billing
31 information.
32  
33 =cut
34  
35 package Business::Billing::TMobile::UK;
36  
37 # pragmata
38 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 # Standard Perl Library and CPAN modules
43 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use Encode qw(from_to);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use HTML::TreeBuilder;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 1 $VERSION = '0.16';
49  
50  
51 =head1 CLASS METHODS
52  
53 =head2 new
54  
55 new(username => $username, password => $password)
56  
57 =cut
58  
59 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
60 1 my($class, %options) = @_;
61  
62 1 foreach my $opt (qw(username password)){
63 2 ▶ croak "Option $opt not provided\n" unless $options{$opt};
Branch: 1 branch
BranchTrueFalseTotal
unless $options{$opt} 0 2 2
64 }
65  
66 my $self = {
67 username => $options{username},
68 password => $options{password},
69 1 };
70  
71 1 bless $self, $class;
72 1 return $self;
73 }
74  
75 =head1 OBJECT METHODS
76  
77 =head2 get_allowances
78  
79 get_allowances()
80  
81 Logs into the My Account section of the T-Mobile website and parses out the
82 Allowance information if available.
83  
84 =cut
85  
86 0 ▶sub get_allowances {
Subroutine get_allowances: not called CC=1 SCAR=6.9
Pod documented
87 0 my($self) = @_;
88  
89 0 my $content = $self->_login();
90  
91 0 return $self->_parse_allowances($content);
92 }
93  
94 # PRIVATE METHODS
95  
96 0 ▶sub _login {
Subroutine _login: not called CC=1 SCAR=6.9
97 0 my($self) = @_;
98  
99 0 my $agent = WWW::Mechanize->new();
100 0 $agent->get('http://www.t-mobile.co.uk/Dispatcher');
101 0 $agent->form_name('login');
102 0 $agent->current_form->value('username', $self->{username});
103 0 $agent->current_form->value('password', $self->{password});
104 0 $agent->submit();
105 0 return $agent->content;
106  
107 }
108  
109 0 ▶sub _logout {
Subroutine _logout: not called CC=1 SCAR=6.9
110 0 croak "Not implemented yet\n";
111 }
112  
113 1 ▶sub _parse_allowances {
Subroutine _parse_allowances: called CC=3 SCAR=11.0
114 1 my($self, $html) = @_;
115  
116 # Build Tree
117 1 my $tree = HTML::TreeBuilder->new_from_content($html);
118  
119 # Find the td tag with the news stories in it
120 # Thankfully it has a width which no other
121 1 my @tags = $tree->look_down(_tag => 'tr', id=> 'allwValueRow');
122  
123 1 ▶ croak "Allowances not found on T-Mobile site at present time\n" unless @tags;
Branch: 1 branch
BranchTrueFalseTotal
unless @tags 0 1 1
124  
125 1 my @text = grep {!/^$/ } map {$_->as_text; } @tags;
126
127  
128 1 my @allowances;
129  
130 1 foreach my $text (@text) {
131 2 from_to($text, 'utf8', 'iso-8859-1');
132 # There seems to be some weird encoding. Most of it dissappears with the conversion from UTF-8 but there are also stray ? chars
133 2 $text =~ s/^(\d+)[?](\D+)$/$1 $2/;
134 2 push @allowances, $text;
135 }
136  
137 1 return \@allowances;
138  
139 }
140  
141 1 1;
142  
143 =head1 INSTALLATION
144  
145 This module uses Module::Build for its installation. To install this module type
146 the following:
147  
148 perl Build.PL
149 ./Build
150 ./Build test
151 ./Build install
152  
153  
154 If you do not have Module::Build type:
155  
156 perl Makefile.PL
157  
158 to fetch it. Or use CPAN or CPANPLUS and fetch it "manually".
159  
160 =head1 DEPENDENCIES
161  
162 This module requires these other modules and libraries:
163  
164 Test::More
165  
166 Test::More is only required for testing purposes
167  
168 This module has these optional dependencies:
169  
170 Test::Distribution
171  
172 This is just requried for testing purposes.
173  
174 =head1 TODO
175  
176 If find this module useful please do let me know and I'll spend more effort on
177 expanding/improving it. All enhancement requests are welcome.
178  
179 =over
180  
181 =item *
182  
183 _logout method (just to be nice)
184  
185 =back
186  
187 =head1 BUGS
188  
189 To report a bug or request an enhancement use CPAN's excellent Request Tracker,
190 either via the web:
191  
192 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Business-Billing-TMobile-UK>
193  
194 or via email:
195  
196 C<bug-business-billing-tmobile-uk@rt.cpan.org>
197  
198 =head1 SOURCE AVAILABILITY
199  
200 This source is part of a SourceForge project which always has the
201 latest sources in svn.
202  
203 http://sourceforge.net/projects/sagar-r-shah/
204  
205 =head1 AUTHOR
206  
207 Sagar R. Shah, C<< <sagarshah@softhome.net> >>
208  
209 =head1 COPYRIGHT
210  
211 Copyright 2005 Sagar R. Shah, All Rights Reserved.
212  
213 This program is free software; you can redistribute it and/or modify it
214 under the same terms as Perl itself.
215  
216 =cut
↑ Summary