| 1 | package Apache2::WurflPremium; | ||
| 2 | |||
| 3 | |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Data::Dumper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | |||
| 9 | 0 | ▶ | use Apache2::Const; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | use Apache2::RequestRec; | ||
| 11 | use APR::Table; | ||
| 12 | use Apache2::Module (); | ||
| 13 | use Apache2::ServerUtil; | ||
| 14 | use Net::WURFL::ScientiaMobile; | ||
| 15 | use Net::WURFL::ScientiaMobile::Cache::Cache; | ||
| 16 | use Cache::File; | ||
| 17 | |||
| 18 | |||
| 19 | # ABSTRACT: A module that the Wurfl Perl client to retrieve capabilities data from the Wurfl server | ||
| 20 | |||
| 21 | =pod | ||
| 22 | |||
| 23 | =head1 NAME | ||
| 24 | |||
| 25 | Apache2::WurflPremium -A module that the Wurfl Perl client to retrieve capabilities data from the Wurfl server | ||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | =head1 DESCRIPTION | ||
| 30 | |||
| 31 | -A module that the Wurfl Perl client to retrieve capabilities data from the Wurfl server | ||
| 32 | |||
| 33 | =head1 METHODS | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | use 5.010; | ||
| 38 | use strict; | ||
| 39 | use warnings; | ||
| 40 | |||
| 41 | our $VERSION = '0.01'; | ||
| 42 | |||
| 43 | =pod | ||
| 44 | |||
| 45 | =head2 handler | ||
| 46 | |||
| 47 | The handler retrieves the user_agens and the api key. | ||
| 48 | It then checks the cache for existing data | ||
| 49 | If none is there is retrieves data from the Wurfl server | ||
| 50 | and sets the environment accordingly. | ||
| 51 | |||
| 52 | =cut | ||
| 53 | |||
| 54 | sub get_config { | ||
| 55 | Apache2::Module::get_config('Apache2::Wurfl::Parameters', @_); | ||
| 56 | } | ||
| 57 | |||
| 58 | sub handler { | ||
| 59 | my $r = shift; | ||
| 60 | |||
| 61 | #get user agent | ||
| 62 | my $headers_in = $r->headers_in; | ||
| 63 | my $user_agent = $headers_in->get('User-Agent'); | ||
| 64 | |||
| 65 | #get api key | ||
| 66 | my $s = $r->server; | ||
| 67 | my $dir_cfg = get_config($s, $r->per_dir_config); | ||
| 68 | my $api_key = $dir_cfg->{WurflAPIKey}; | ||
| 69 | |||
| 70 | #load wurflcloud client library with local file cache | ||
| 71 | my $cache = Net::WURFL::ScientiaMobile::Cache::Cache->new( | ||
| 72 | cache => Cache::File->new(cache_root => '/tmp/wurfl_cacheroot')); | ||
| 73 | my $scientiamobile = Net::WURFL::ScientiaMobile->new( | ||
| 74 | api_key => $api_key, | ||
| 75 | cache => $cache, | ||
| 76 | ); | ||
| 77 | |||
| 78 | #run device detection and retrieve data | ||
| 79 | my $capabilities; | ||
| 80 | my %env = %ENV; | ||
| 81 | $env{'User-Agent'} = $user_agent unless $env{'User-Agent'}; | ||
| 82 | |||
| 83 | $scientiamobile->detectDevice(\%env); | ||
| 84 | $capabilities = $scientiamobile->capabilities(); | ||
| 85 | |||
| 86 | #load capabilities into apache environment | ||
| 87 | foreach my $key (keys %{$capabilities}) { | ||
| 88 | my $upperkey = uc($key); | ||
| 89 | $r->subprocess_env("WURFL_$upperkey" => $capabilities->{$key}); | ||
| 90 | } | ||
| 91 | |||
| 92 | return Apache2::Const::OK; | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | =pod | ||
| 98 | |||
| 99 | |||
| 100 | =cut | ||
| 101 | |||
| 102 | |||
| 103 | 1; | ||