View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Luca Passani > Plack-Middleware-WURFL-ScientiaMobile > Plack::Middleware::WURFL::ScientiaMobile



Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  


Plack::Middleware::WURFL::ScientiaMobile - Query the ScientiaMobile webservice in middleware


    use Plack::Builder;
    builder {
        enable 'WURFL::ScientiaMobile', config => {
            api_key => '...',


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.

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.

    use Plack::Builder;
    builder {
        enable 'WURFL::ScientiaMobile', config => {
            api_key => '...',
            cache   => Net::WURFL::ScientiaMobile::Cache::Cookie->new,


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.



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.


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 <>


Copyright 2012, ScientiaMobile, Inc.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: