Plack::Middleware::DetectMobileBrowsers - Automatically set a flag in the environment if a mobile client is detected
version 0.05
use Plack::Builder; my $app = sub { ... } # as usual builder { enable 'DetectMobileBrowsers'; # or: enable 'DetectMobileBrowsers', env_key => 'mobileDevice'; # or: enable 'DetectMobileBrowsers', tablets_as_mobile => 1; $app; }; # ... and later ... if ( $yourApp->theEnv->{'mobile_client'} ) { # ... do something ... }
This Plack middleware uses the regular expression provided by http://detectmobilebrowsers.com/ to analyse the User-Agent HTTP header and to set an environment flag to either a true or false value depending on the detection of a mobile client device.
User-Agent
The default name of the flag in the environment is mobile_client, but this can be customized by setting the env_key option when enabling this middleware.
mobile_client
env_key
It might make sense to use psgix.mobile_client by default instead, but the PSGI spec states that the "'psgix.' prefix is reserved for officially blessed extensions" - which does not apply to this module. You may, however, set the key to psgix.mobile_client yourself by using the env_key option mentioned before.
psgix.mobile_client
2014-08-01
You may specify the following option when enabling the middleware:
Set the name of the entry in the environment hash.
tablets_as_mobile
Determines if tablets are considered to be mobile devices. By default they are not; set this param to a true value to change the default behaviour.
Plack, Plack::Middleware, http://detectmobilebrowsers.com/
Heiko Jansen <hjansen@cpan.org>
This software is copyright (c) 2015 by Heiko Jansen.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Plack::Middleware::DetectMobileBrowsers, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::DetectMobileBrowsers
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::DetectMobileBrowsers
For more information on module installation, please visit the detailed CPAN module installation guide.