| 1 | package HTTP::MobileAgent; | ||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 4 | 9 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 5 | 9 | $VERSION = '0.23_03'; | |||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||
| 7 | 9 | ▶ | use HTTP::MobileAgent::Request; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||
| 9 | 9 | require HTTP::MobileAgent::DoCoMo; | |||||||||||||||||||||||||
| 10 | 9 | require HTTP::MobileAgent::JPhone; | |||||||||||||||||||||||||
| 11 | 9 | require HTTP::MobileAgent::EZweb; | |||||||||||||||||||||||||
| 12 | 9 | require HTTP::MobileAgent::AirHPhone; | |||||||||||||||||||||||||
| 13 | 9 | require HTTP::MobileAgent::NonMobile; | |||||||||||||||||||||||||
| 14 | 9 | require HTTP::MobileAgent::Display; | |||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||
| 16 | 9 | ▶ | use vars qw($MobileAgentRE); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 17 | # this matching should be robust enough | ||||||||||||||||||||||||||
| 18 | # detailed analysis is done in subclass's parse() | ||||||||||||||||||||||||||
| 19 | 9 | my $DoCoMoRE = '^DoCoMo/\d\.\d[ /]'; | |||||||||||||||||||||||||
| 20 | 9 | my $JPhoneRE = '^J-PHONE/\d\.\d'; | |||||||||||||||||||||||||
| 21 | 9 | my $VodafoneRE = '^Vodafone/\d\.\d'; | |||||||||||||||||||||||||
| 22 | 9 | my $VodafoneMotRE = '^MOT-'; | |||||||||||||||||||||||||
| 23 | 9 | my $EZwebRE = '^(?:KDDI-[A-Z]+\d+[A-Z]? )?UP\.Browser\/'; | |||||||||||||||||||||||||
| 24 | 9 | my $AirHRE = '^Mozilla/3\.0\(DDIPOCKET\;'; | |||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||
| 26 | 9 | $MobileAgentRE = qr/(?:($DoCoMoRE)|($JPhoneRE)|($VodafoneRE)|($VodafoneMotRE)|($EZwebRE)|($AirHRE))/; | |||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||
| 28 | sub new { | ||||||||||||||||||||||||||
| 29 | 566 | ▶ | my($class, $stuff) = @_; | ||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||
| 30 | 566 | my $request = HTTP::MobileAgent::Request->new($stuff); | |||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||
| 32 | # parse UA string | ||||||||||||||||||||||||||
| 33 | 566 | my $ua = $request->get('User-Agent'); | |||||||||||||||||||||||||
| 34 | 566 | my $sub = 'NonMobile'; | |||||||||||||||||||||||||
| 35 | 566 | ▶ | if ($ua =~ /$MobileAgentRE/) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 36 | 398 | ▶ | $sub = $1 ? 'DoCoMo' : $2 ? 'JPhone' : $3 ? 'JPhone' : $4 ? 'JPhone' : $5 ? 'EZweb' : 'AirHPhone'; | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||
| 39 | 566 | my $self = bless { _request => $request }, "$class\::$sub"; | |||||||||||||||||||||||||
| 40 | 566 | $self->parse; | |||||||||||||||||||||||||
| 41 | 566 | return $self; | |||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||
| 45 | sub user_agent { | ||||||||||||||||||||||||||
| 46 | 759 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
user_agent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 47 | 759 | $self->get_header('User-Agent'); | |||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||
| 50 | sub get_header { | ||||||||||||||||||||||||||
| 51 | 772 | ▶ | my($self, $header) = @_; | ||||||||||||||||||||||||
|
Subroutine
get_header: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 52 | 772 | $self->{_request}->get($header); | |||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||
| 55 | # should be implemented in subclasses | ||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub parse { die } | ||||||||||||||||||||||||
|
Subroutine
parse: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub _make_display { die } | ||||||||||||||||||||||||
|
Subroutine
_make_display: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||
| 59 | 318 | ▶ | sub name { shift->{name} } | ||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||
| 61 | sub display { | ||||||||||||||||||||||||||
| 62 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
display: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||
| 63 | 7 | ▶ | unless ($self->{display}) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 64 | 7 | $self->{display} = $self->_make_display; | |||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||
| 66 | 7 | return $self->{display}; | |||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||
| 69 | # utility for subclasses | ||||||||||||||||||||||||||
| 70 | sub make_accessors { | ||||||||||||||||||||||||||
| 71 | 54 | ▶ | my($class, @attr) = @_; | ||||||||||||||||||||||||
|
Subroutine
make_accessors: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 72 | 54 | for my $attr (@attr) { | |||||||||||||||||||||||||
| 73 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 74 | 315 | ▶ | *{"$class\::$attr"} = sub { shift->{$attr} }; | ||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||
| 78 | sub no_match { | ||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
no_match: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 80 | 0 | require Carp; | |||||||||||||||||||||||||
| 81 | 0 | ▶ | Carp::carp($self->user_agent, ": no match. Might be new variants. ", | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 82 | "please contact the author of HTTP::MobileAgent!") if $^W; | ||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||
| 85 | 383 | ▶ | sub is_docomo { 0 } | ||||||||||||||||||||||||
|
Subroutine
is_docomo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 86 | 482 | ▶ | sub is_j_phone { 0 } | ||||||||||||||||||||||||
|
Subroutine
is_j_phone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 87 | 180 | ▶ | sub is_vodafone { 0 } | ||||||||||||||||||||||||
|
Subroutine
is_vodafone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 88 | 405 | ▶ | sub is_ezweb { 0 } | ||||||||||||||||||||||||
|
Subroutine
is_ezweb: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub is_airh_phone { 0 } | ||||||||||||||||||||||||
|
Subroutine
is_airh_phone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub is_non_mobile { 0 } | ||||||||||||||||||||||||
|
Subroutine
is_non_mobile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub is_tuka { 0 } | ||||||||||||||||||||||||
|
Subroutine
is_tuka: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||
| 93 | sub is_wap1 { | ||||||||||||||||||||||||||
| 94 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
is_wap1: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||
| 95 | 3 | ▶ | $self->is_ezweb && ! $self->is_wap2; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||
| 98 | sub is_wap2 { | ||||||||||||||||||||||||||
| 99 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
is_wap2: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||
| 100 | 10 | ▶ | $self->is_ezweb && $self->xhtml_compliant; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub carrier { undef } | ||||||||||||||||||||||||
|
Subroutine
carrier: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub carrier_longname { undef } | ||||||||||||||||||||||||
|
Subroutine
carrier_longname: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||
| 106 | 9 | 1; | |||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||