NAME
Dancer::Plugin::DetectRobots - Dancer plugin to determine if the user is a robot
VERSION
version 0.6
DESCRIPTION
A plugin for Dancer applications providing a keyword, is_robot, which tests request->user_agent and returns 1 if the user_agent appears to be a robot.
To use, simply call is_robot whenever/wherever you would like to know if the user is a bot or a human. For example, if you would like to skip logging for bots
if( ! is_robot ) {
log_message("your log message");
}
The plugin has been written to be as efficient as possible. The list of Robot UserAgent strings is only matched against request->user_agent once per session.
This is done by storing its results in a session variable so a session engine must be enabled. Session::Cookie would be a poor choice since the optimization will be lost when dealing with a search engine or robot.
The first call to is_robot in a session checks to see if the session variable has been set, if if it has, it returns 0 or 1 based upon the session variable.
By default the session variable key is "robot_client"
The check is done against the list of UserAgent strings used by AWStats. There are three levels of testing, BASIC which matches AWStats LevelForRobotsDetection=1, EXTENDED which matches LevelForRobotsDetection=2 and GENERIC which is a very lax test.
By default the level is set to BASIC
You can change these settings. See CONFIGURATION
NAME
Dancer::Plugin::DetectRobots - A plugin to detect if the HTTP_USER_AGENT matches a known search engine or robot string.
SYNOPSYS
In your configuration, make sure you have session configured. Of course you can use any session engine.
session: "simple"
In your Dancer App
use Dancer;
use Dancer::Plugin::DetectRobots;
if( is_robot ) {
...
}
else {
processing goes here
...
}
METHODS
is_robot
# returns 1 if the HTTP_USER_AGENT as returned by request->user_agent
# matches one of the strings used by AWStats to detect search engines and
# bots
if ( is_robot ) {
..
}
CONFIGURATION
With no configuration whatsoever, the plugin will work fine, thus contributing to the keep it simple motto of Dancer.
configuration default values
These are the default values. See below for a description of the keys
plugins:
DetectRobots:
session_key: robot_client
type: BASIC
configuration description
- session_key
-
The name of the session key which is used to store the results of the robot test lookup
Default :
robot_client
- type
-
This value determinse which of 3 lists the search tests against. BASIC - this is the same as AWStats LevelForRobotsDetection=1 It tests for major search engines and know bots EXTENDED - this is the same as AWStats LevelForRobotsDetection=2 It tests for major search engines and know bots as in BASIC plus about 800 minor bots and search engines. GENERIC - this is a very simple test that only looks for a couple of dozen generic bot strings, e.g. robot, crawl, hunter, spider ...
Default :
BASIC
COPYRIGHT
This software is copyright (c) 2014 by Dan Busarow <dan@buildingonline.com>.
LICENCE
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
AUTHORS
This module has been written by Dan Busarow <dan@buildingonline.com> based upon Plack::Middleware::DetectRobots by Heiko Jansen <hjansen@cpan.org>
SEE ALSO
AUTHOR
Dan Busarow
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Dan Busarow
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.