Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Detects and optionally redirects mobile browsers using plack and dancer

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 README

This Dancer plack middleware detects mobile browsers and optionally redirects.  The regex used is straight
from  Thanks to Chad Smith for all his hard work.

To install make the following directories under APPLICATION/lib


Copy to APPLICATION/lib/Dancer/Middleware

In your dancer apps config.yaml add the following lines, note the redirect_to and the line following is optional.

    - "+Dancer::Middleware::SmartPhoneDetection"
    - redirect_to
    - ""

DetectMobileBrowser sets an environment variable MOBILE_BROWSER.  This variable can be used in your routes thusly

get '/' => sub {
	if(request->env->{ MOBILE_BROWSER }) {
		debug('Smart phone yeah !');
	} else {
		debug('Boring standard browser yeah !');

Or if the redirect_to variable is set the request will be redirected if the browser is detected to be a mobile browser.
Something went wrong with that request. Please try again.