| 1 | package Test::MobileAgent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | our @EXPORT = qw/test_mobile_agent/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | our @EXPORT_OK = qw/test_mobile_agent_env | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | test_mobile_agent_headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | test_mobile_agent_list/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 9 | our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1053 | ▶ | sub test_mobile_agent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test_mobile_agent: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1053 | my %env = test_mobile_agent_env(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1053 | $ENV{$_} = $env{$_} for keys %env; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1053 | ▶ | return %env if defined wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2106 | ▶ | sub test_mobile_agent_env { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test_mobile_agent_env: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2106 | my ($agent, %extra_headers) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2106 | my ($vendor, $type) = _find_vendor($agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2106 | my $class = _load_class($vendor); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2106 | return $class->env($type, %extra_headers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1053 | ▶ | sub test_mobile_agent_headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test_mobile_agent_headers: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1053 | my %env = test_mobile_agent_env(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1053 | require HTTP::Headers::Fast; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1053 | my $headers = HTTP::Headers::Fast->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1053 | foreach my $name (keys %env) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1518 | (my $short_name = $name) =~ s/^HTTP[-_]//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1518 | $headers->header($short_name => $env{$name}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1053 | $headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 14 | ▶ | sub test_mobile_agent_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test_mobile_agent_list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 14 | my ($vendor, $type) = _find_vendor(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 14 | my $class = _load_class($vendor); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 14 | return $class->list($type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2120 | ▶ | sub _find_vendor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_vendor: called CC=19 SCAR=31.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2120 | my $agent = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2120 | ▶ | if ($agent =~ /^[a-z]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 22 | ▶ | if ($agent =~ /^ip(?:hone|[oa]d)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $agent =~ tr/p/P/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return ("Smartphone", "($agent;"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | elsif ($agent eq 'android') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | return ("Smartphone", 'Android'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 22 | return (ucfirst($agent), ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | elsif ($agent =~ /^[a-z]+\./) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | my ($vendor, $type) = split /\./, $agent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | if ($vendor =~ /^(ip(?:hone|[oa]d)|android)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $type = "$vendor.+$type"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return ("Smartphone", qr/$type/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | if ($type =~ /^iP(?:hone|[oa]d)$/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $type = "($type;"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 4 | return (ucfirst $vendor, $type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # do some guesswork | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2094 | my $vendor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2094 | ▶ | if ($agent =~ /^DoCoMo/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 918 | return ('Docomo', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | elsif ($agent =~ /^J\-PHONE/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 236 | return ('Jphone', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | elsif ($agent =~ /^KDDI\-/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 60 | return ('Ezweb', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | elsif ($agent =~ /^UP\.Browser/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 242 | return ('Ezweb', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | elsif ($agent =~ /DDIPOCKET/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 6 | return ('Airh', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif ($agent =~ /WILLCOM/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 16 | return ('Airh', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | elsif ($agent =~ /^Vodafone/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 56 | return ('Vodafone', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | elsif ($agent =~ /^MOT/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 10 | return ('Vodafone', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | elsif ($agent =~ /^Nokia/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | return ('Vodafone', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | elsif ($agent =~ /^SoftBank/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 216 | return ('Softbank', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | elsif ($agent =~ /\(iP(?:hone|[ao]d);/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return ('Smartphone', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | elsif ($agent =~ /Android/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return ('Smartphone', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 330 | return ('Nonmobile', $agent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 2120 | ▶ | sub _load_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_class: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2120 | my $vendor = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2120 | my $class = "Test::MobileAgent::$vendor"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2120 | eval "require $class"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2120 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $class = 'Test::MobileAgent::Nonmobile'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | require Test::MobileAgent::Nonmobile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2120 | return $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||