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