Kevin L. Kane > Catalyst-Plugin-EnvironmentDetector-0.01 > Catalyst::Plugin::EnvironmentDetector



Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  


Catalyst::Plugin::EnvironmentDetector - Catalyst plugin for environment detection


    use Catalyst 'EnvironmentDetector';

        environmentdetector => { 
            production => { hostname => '' },
            test => { env => [ 'db_dsn', '' ] } 

    if( $c->is_environment( 'production' ) {
        # do things only on production
    } elsif ( $c->is_environment( 'test' ) ) {
        # do something else only on test


This plugin is intended to provide a generic way to detect what environment your catalyst instance is currently operating in. This is good for when you need/want to modify behavior depending on the context that you are running the instance in.

This is done in a generic way so if the nature of the environment ever changes you can simply update the config and it will work rather than propagating the change to every place in your code you may have needed to detect environments.

Why would you want to do this?: Changing the authentication behavior in test or development Changing email recipients for test or development Circumventing security policies in a dedicated test environment


Supported methods of environment detection:

Environment variables can be configured as follows:

        environmentdetector => { 
            test => { env => [ 'db_dsn', '' ] } 

'test' is the environment key, env signifies the environment variables method of detection and the array specifies the ENV key to use and the pattern to match against.

Hostname based detection can be configured as follows:

        environmentdetector => { 
            production => { hostname => '' }

'production' is the environment key, hostname signifies the hostname method of detection and the string it keys to is the pattern that should be matched.



Accepts a string that is the environment name that you are trying to detect. This environment name must be set in this plugins configuration in order for the detection to work. Trying to detect an environment that has no configuration will cause this function to return undef. Under normal circumstances it will return 1 if the environment matches and 0 it if does not.



Kevin L. Kane, <>


Copyright (C) 2013 by Kevin L. Kane

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

syntax highlighting: