Plack::Middleware::WURFL::ScientiaMobile - Query the ScientiaMobile webservice in middleware
use Plack::Builder; builder { enable 'WURFL::ScientiaMobile', config => { api_key => '...', }; $app; };
This middleware is intended to act as a bridge between the WURFL ScientiaMobile webservice and PSGI-based web applications. It does two things: it processes each incoming HTTP request through the detectDevice() method of Net::WURFL::ScientiaMobile and it places the pre-populated ScientiaMobile object inside the $env structure that is passed to your web application. You can easily access it from your web framework of choice and apply your device-specific logic.
detectDevice()
$env
If you configure the ScientiaMobile object with a Cache cache provider, the middleware will be smart enough to interact with it for reading and writing cookies.
Cache
use Plack::Builder; builder { enable 'WURFL::ScientiaMobile', config => { api_key => '...', cache => Net::WURFL::ScientiaMobile::Cache::Cookie->new, }; $app; };
This middleware accepts the following arguments.
This argument is required. It must be a hashref containing the configuration options for the Net::WURFL::ScientiaMobile client object. The only required option is api_key, but check the documentation for Net::WURFL::ScientiaMobile to learn about all possible options.
api_key
Returns the PSGI $env key under which you'd expect to find either an instance of Net::WURFL::ScientiaMobile (pre-populated with the device capabilities) or an exception object.
Given a Plack $env, returns the Net::WURFL::ScientiaMobile object containing the device capabilities. If the call to detectDevice() threw an exception instead of succeeding, this method returns undef.
For example, in your web application:
use Plack::Middleware::WURFL::ScientiaMobile; sub my_handler { ... my $env = ...; # your web framework provides this my $scientiamobile = Plack::Middleware::WURFL::ScientiaMobile->get_from_env($env); if (!$scientiamobile) { my $error = Plack::Middleware::WURFL::ScientiaMobile->get_error_from_env($env); .... } .... }
Refer to the documentation of your web framework to learn how to access $env. For example, Catalyst provides it in $ctx->request->env, Dancer provides it in request->env, Mojo provides it in $tx->req->env.
$ctx->request->env
request->env
$tx->req->env
Given a Plack $env, returns the Exception::Class object representing the failure. If no exception was caught, undef is returned.
Refer to the documentation of Net::WURFL::ScientiaMobile for an explanation of possible exceptions.
Plack, Plack::Middleware, Net::WURFL::ScientiaMobile
Alessandro Ranellucci <aar@cpan.org>
<aar@cpan.org>
Copyright 2012, ScientiaMobile, Inc.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Plack::Middleware::WURFL::ScientiaMobile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::WURFL::ScientiaMobile
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::WURFL::ScientiaMobile
For more information on module installation, please visit the detailed CPAN module installation guide.