| 1 | package Catalyst::Plugin::ConfigurablePathTo; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Path::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Catalyst::Plugin::ConfigurablePathTo - Provides a configurable C<path_to()> | ||||||||||
| 11 | |||||||||||
| 12 | =head1 VERSION | ||||||||||
| 13 | |||||||||||
| 14 | Version 0.01 | ||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | 2 | our $VERSION = '0.01'; | |||||||||
| 19 | |||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||
| 21 | |||||||||||
| 22 | This plugin provides a way to have generic configurable paths in L<Catalyst>. | ||||||||||
| 23 | |||||||||||
| 24 | # in myapp.yml | ||||||||||
| 25 | |||||||||||
| 26 | path_to: | ||||||||||
| 27 | |||||||||||
| 28 | profiles: /usr/local/profiles | ||||||||||
| 29 | |||||||||||
| 30 | tempfiles: /tmp/myapp_tempfiles | ||||||||||
| 31 | |||||||||||
| 32 | ... | ||||||||||
| 33 | |||||||||||
| 34 | # in some Catalyst controller | ||||||||||
| 35 | |||||||||||
| 36 | # 'profiles' is defined in the config file, so you'll | ||||||||||
| 37 | # get '/usr/local/profiles' back | ||||||||||
| 38 | my $profiles_path = $c->path_to('profiles'); | ||||||||||
| 39 | |||||||||||
| 40 | # it also correctly creates the paths, using Path::Class | ||||||||||
| 41 | # you'll get '/tmp/myapp_tempfiles/file.tmp' back | ||||||||||
| 42 | my $temp_path = $c->path_to('tempfiles', 'file.tmp'); | ||||||||||
| 43 | |||||||||||
| 44 | # performs as the original path_to() would if it's not defined | ||||||||||
| 45 | # in the config file | ||||||||||
| 46 | my #other_path = $c->path_to('other'); | ||||||||||
| 47 | |||||||||||
| 48 | =head1 METHODS | ||||||||||
| 49 | |||||||||||
| 50 | =cut | ||||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | =head2 $c->path_to( @path ) | ||||||||||
| 54 | |||||||||||
| 55 | If C<$path[0]> represents an already configured path in the application | ||||||||||
| 56 | config file, C<$path[0]> is replaced with the configured path and C<@path> | ||||||||||
| 57 | is merged into a L<Path::Class> object. | ||||||||||
| 58 | |||||||||||
| 59 | Otherwise, C<@path> is merged with C<$c-E<gt>config-E<gt>{home}> into a | ||||||||||
| 60 | L<Path::Class> object. | ||||||||||
| 61 | |||||||||||
| 62 | =cut | ||||||||||
| 63 | 0 | ▶ | sub path_to { | ||||||||
|
Subroutine
path_to: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 64 | 0 | my ($c, @path) = @_; | |||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | if (exists $c->config->{path_to}->{$path[0]}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $path[0] = $c->config->{path_to}->{$path[0]}; | |||||||||
| 68 | } | ||||||||||
| 69 | else { | ||||||||||
| 70 | 0 | unshift(@path, $c->config->{home}); | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | # code adapted (i.e. almost shamelessly ripped) from Catalyst.pm v5.65 | ||||||||||
| 74 | 0 | my $path = dir(@path); | |||||||||
| 75 | 0 | ▶ | if (-d $path) {return $path} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | else {return file(@path)} | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | =head1 AUTHOR | ||||||||||
| 80 | |||||||||||
| 81 | Nilson Santos Figueiredo JĂșnior, C<< <nilsonsfj at cpan.org> >> | ||||||||||
| 82 | |||||||||||
| 83 | =head1 BUGS | ||||||||||
| 84 | |||||||||||
| 85 | Please report any bugs or feature requests directly to the author. | ||||||||||
| 86 | If you ask nicely it will probably get fixed or implemented. | ||||||||||
| 87 | |||||||||||
| 88 | =head1 SUPPORT | ||||||||||
| 89 | |||||||||||
| 90 | You can find documentation for this module with the perldoc command. | ||||||||||
| 91 | |||||||||||
| 92 | perldoc Catalyst::Plugin::ConfigurablePathTo | ||||||||||
| 93 | |||||||||||
| 94 | You can also look for information at: | ||||||||||
| 95 | |||||||||||
| 96 | =over 4 | ||||||||||
| 97 | |||||||||||
| 98 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 99 | |||||||||||
| 100 | L<http://annocpan.org/dist/Catalyst-Plugin-ConfigurablePathTo> | ||||||||||
| 101 | |||||||||||
| 102 | =item * CPAN Ratings | ||||||||||
| 103 | |||||||||||
| 104 | L<http://cpanratings.perl.org/d/Catalyst-Plugin-ConfigurablePathTo> | ||||||||||
| 105 | |||||||||||
| 106 | =item * RT: CPAN's request tracker | ||||||||||
| 107 | |||||||||||
| 108 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-ConfigurablePathTo> | ||||||||||
| 109 | |||||||||||
| 110 | =item * Search CPAN | ||||||||||
| 111 | |||||||||||
| 112 | L<http://search.cpan.org/dist/Catalyst-Plugin-ConfigurablePathTo> | ||||||||||
| 113 | |||||||||||
| 114 | =back | ||||||||||
| 115 | |||||||||||
| 116 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 117 | |||||||||||
| 118 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 119 | |||||||||||
| 120 | Copyright 2006 Nilson Santos Figueiredo Junior, all rights reserved. | ||||||||||
| 121 | |||||||||||
| 122 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 123 | under the same terms as Perl itself. | ||||||||||
| 124 | |||||||||||
| 125 | =cut | ||||||||||
| 126 | |||||||||||
| 127 | 2 | 1; # End of Catalyst::Plugin::ConfigurablePathTo | |||||||||