line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::ConfigurablePathTo; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
31801
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
75
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
72
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1676
|
use Path::Class; |
|
2
|
|
|
|
|
111666
|
|
|
2
|
|
|
|
|
423
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub path_to { |
64
|
0
|
|
|
0
|
1
|
|
my ($c, @path) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if (exists $c->config->{path_to}->{$path[0]}) { |
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
|
0
|
|
|
|
|
if (-d $path) {return $path} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
1; # End of Catalyst::Plugin::ConfigurablePathTo |