blib/lib/MMS/Mail/Provider.pm

filter: Statementstmt 32.3% 11 / 34 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 34.6% 17 / 49 CC 4 SCAR 22.7
CC
4
Cov
28%
retrieve_phone_number
20.0
new
2.0
parse
2.0
CRAP 9.7
↑ Summary
1 package MMS::Mail::Provider;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use MMS::Mail::Message::Parsed;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 MMS::Mail::Provider - This provides a base class for parsing an MMS::Mail::Message object into a MMS::Mail::Message::Parsed object.
11  
12 =head1 VERSION
13  
14 Version 0.07
15  
16 =cut
17  
18 2 our $VERSION = '0.07';
19  
20 =head1 SYNOPSIS
21  
22 This class provides a parse method for parsing an MMS::Mail::Message object into an MMS::Mail::Message::Parsed object for 'generic' MMS messages (or ones that cannot be identified as coming from a specific provider).
23  
24 =head1 METHODS
25  
26 The following are the top-level methods of the MMS::Mail::Provider class.
27  
28 =head2 Constructor
29  
30 =over
31  
32 =item C<new()>
33  
34 Return a new MMS::Mail::Provider object.
35  
36 =back
37  
38 =head2 Regular Methods
39  
40 =over
41  
42 =item C<parse> MMS::Mail::Message
43  
44 Instance method - The C<parse> method parses the MMS::Mail::Message and returns an MMS::Mail::Message::Parsed.
45  
46 =item C<retrieve_phone_number> STRING
47  
48 Instance method - This method splits the provided string on @ and returns the first list element from the split, replacing any leading + character with 00. This seems to be the convention used by most UK providers and may work for other non-UK providers.
49  
50 =back
51  
52 =head1 AUTHOR
53  
54 Rob Lee, C<< <robl at robl.co.uk> >>
55  
56 =head1 BUGS
57  
58 Please report any bugs or feature requests to
59 C<bug-mms-mail-provider@rt.cpan.org>, or through the web interface at
60 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MMS-Mail-Provider>.
61 I will be notified, and then you'll automatically be notified of progress on
62 your bug as I make changes.
63  
64 =head1 NOTES
65  
66 Please read the Perl artistic license ('perldoc perlartistic') :
67  
68 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
69 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
70 OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
71  
72 =head1 ACKNOWLEDGEMENTS
73  
74 As per usual this module is sprinkled with a little Deb magic.
75  
76 =head1 COPYRIGHT & LICENSE
77  
78 Copyright 2005 Rob Lee, all rights reserved.
79  
80 This program is free software; you can redistribute it and/or modify it
81 under the same terms as Perl itself.
82  
83 =head1 SEE ALSO
84  
85 L<MMS::Mail::Message>, L<MMS::Mail::Message::Parsed>, L<MMS::Mail::Provider>
86  
87 =cut
88  
89 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
90 0 my $type = shift;
91 0 my $self = {};
92 0 bless $self, $type;
93  
94 0 return $self;
95 }
96  
97 0 ▶sub parse {
Subroutine parse: not called CC=1 SCAR=6.9
Pod documented
98  
99 0 my $self = shift;
100 0 my $message = shift;
101  
102 0 my $parsed = new MMS::Mail::Message::Parsed( message=>$message);
103  
104 0 $parsed->header_subject($message->header_subject);
105 0 $parsed->body_text($message->body_text);
106  
107 0 $parsed->images($parsed->retrieve_attachments('^image'));
108 0 $parsed->videos($parsed->retrieve_attachments('^video'));
109  
110 0 return $parsed;
111  
112 }
113  
114 0 ▶sub retrieve_phone_number {
Subroutine retrieve_phone_number: not called CC=4 SCAR=30.0
Pod documented
115  
116 0 my $self = shift;
117 0 my $from = shift;
118  
119 0 ▶ unless (defined($from)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $from) 0 0 0
120 0 return undef;
121 }
122  
123 # Set mobile number property to a VALID number
124 #
125 # This works on the idea the form is in format
126 # 0000000000@someprovider.net
127 #
128
129 0 my ($number, undef) = split /\@/, $from;
130 0 ▶ if ($number =~ /^\+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number =~ /^\+/) { } 0 0 0
131 0 $number =~ s/^\+/00/;
132 } else {
133 0 $number = "00".$number;
134 }
135 0 ▶ unless ($number =~ /\D+/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($number =~ /\D+/) 0 0 0
136 0 return $number;
137 }
138 0 return undef;
139  
140 }
141  
142  
143 2 1; # End of MMS::Mail::Provider
↑ Summary