File Coverage

blib/lib/HTTP/MobileAttribute.pm
Criterion Covered Total %
statement 36 37 97.3
branch 2 4 50.0
condition 2 2 100.0
subroutine 12 12 100.0
pod 0 4 0.0
total 52 59 88.1


line stmt bran cond sub pod time code
1             package HTTP::MobileAttribute;
2 26     26   81054 use strict;
  26         60  
  26         937  
3 26     26   138 use warnings;
  26         52  
  26         1201  
4             our $VERSION = '0.23';
5 26     26   855 use 5.008001;
  26         116  
  26         992  
6 26     26   15708 use HTTP::MobileAttribute::Request;
  26         87  
  26         789  
7 26     26   15724 use HTTP::MobileAttribute::CarrierDetector;
  26         81  
  26         845  
8 26     26   28263 use UNIVERSAL::require;
  26         49865  
  26         294  
9              
10             # XXX: This really affects the first time H::MobileAttribute gets loaded
11             sub import {
12 27     27   759286 my $class = shift;
13 27         126 my %args = @_;
14 27   100     200 my $plugins = delete $args{plugins} || [ 'Core' ];
15              
16 27 50       173 if (ref $plugins ne 'ARRAY') {
17 0         0 $plugins = [ $plugins ];
18             }
19 27         126 $class->load_plugins(@$plugins);
20             }
21              
22 53     53 0 252 sub carriers { qw/DoCoMo AirHPhone ThirdForce EZweb NonMobile/ }
23              
24             BEGIN {
25 26     26   3752 for (carriers()) {
26 130 50       2143 "HTTP::MobileAttribute::Agent::$_"->use or die $@;
27             }
28             };
29              
30             sub new {
31 740     740 0 10528 my ($class, $stuff) = @_;
32              
33 740         3749 my $request = HTTP::MobileAttribute::Request->new($stuff);
34              
35             # XXX carrier name detection is actually simple, so instead of
36             # going through the hassle of doing Detector->detect, we simply
37             # create a function that does the right thing and use it
38 740         3720 my $carrier_longname = HTTP::MobileAttribute::CarrierDetector::detect($request->get('User-Agent'));
39              
40 740         2628 my $self = $class->agent_class($carrier_longname)->new({
41             request => $request,
42             carrier_longname => $carrier_longname,
43             });
44 740         36896 $self->parse;
45 740         2058 return $self;
46             }
47              
48 875     875 0 9356 sub agent_class { 'HTTP::MobileAttribute::Agent::' . $_[1] }
49              
50             sub load_plugins {
51 27     27 0 83 my ($class, @plugins) = @_;
52              
53 27         108 for my $carrier (carriers()) {
54 135         7812 $class->agent_class($carrier)->load_plugins(@plugins);
55             }
56             }
57              
58              
59             1;
60             __END__