Skip to content
This repository

HTTPS clone URL

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…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 README
README
Dancer::Middleware::DetectMobileBrowser

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

To install make the following directories under APPLICATION/lib

Dancer/Middleware

Copy DetectMobileBrowser.pm 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.

plack_middlewares:
  -
    - "+Dancer::Middleware::SmartPhoneDetection"
    - redirect_to
    - "http://mobile.quispiam.com"


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.