Catalyst::Plugin::ConfigurablePathTo - Provides a configurable C<path_to()>


Catalyst-Plugin-ConfigurablePathTo documentation Contained in the Catalyst-Plugin-ConfigurablePathTo distribution.

Index


Code Index:

NAME

Top

Catalyst::Plugin::ConfigurablePathTo - Provides a configurable path_to()

VERSION

Top

Version 0.01

SYNOPSIS

Top

This plugin provides a way to have generic configurable paths in Catalyst.

  # in myapp.yml

  path_to:

    profiles: /usr/local/profiles

    tempfiles: /tmp/myapp_tempfiles

    ...

  # in some Catalyst controller

    # 'profiles' is defined in the config file, so you'll
    # get '/usr/local/profiles' back
    my $profiles_path = $c->path_to('profiles');

    # it also correctly creates the paths, using Path::Class
    # you'll get '/tmp/myapp_tempfiles/file.tmp' back
    my $temp_path = $c->path_to('tempfiles', 'file.tmp');

    # performs as the original path_to() would if it's not defined
    # in the config file
    my #other_path = $c->path_to('other');

METHODS

Top

$c->path_to( @path )

If $path[0] represents an already configured path in the application config file, $path[0] is replaced with the configured path and @path is merged into a Path::Class object.

Otherwise, @path is merged with $c->config->{home} into a Path::Class object.

AUTHOR

Top

Nilson Santos Figueiredo Júnior, <nilsonsfj at cpan.org>

BUGS

Top

Please report any bugs or feature requests directly to the author. If you ask nicely it will probably get fixed or implemented.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Catalyst::Plugin::ConfigurablePathTo

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Catalyst-Plugin-ConfigurablePathTo

* CPAN Ratings

http://cpanratings.perl.org/d/Catalyst-Plugin-ConfigurablePathTo

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-ConfigurablePathTo

* Search CPAN

http://search.cpan.org/dist/Catalyst-Plugin-ConfigurablePathTo

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Catalyst-Plugin-ConfigurablePathTo documentation Contained in the Catalyst-Plugin-ConfigurablePathTo distribution.
package Catalyst::Plugin::ConfigurablePathTo;

use warnings;
use strict;

use Path::Class;

our $VERSION = '0.01';

sub path_to {
	my ($c, @path) = @_;
	
	if (exists $c->config->{path_to}->{$path[0]}) {
		$path[0] = $c->config->{path_to}->{$path[0]};
	}
	else {
		unshift(@path, $c->config->{home});
	}

	# code adapted (i.e. almost shamelessly ripped) from Catalyst.pm v5.65
	my $path = dir(@path);
	if (-d $path) {return $path}
	else {return file(@path)}
}

1; # End of Catalyst::Plugin::ConfigurablePathTo