| Catalyst-Plugin-InflateMore documentation | Contained in the Catalyst-Plugin-InflateMore distribution. |
Catalyst::Plugin::InflateMore - Inflates symbols in application config
0.3.$Revision: 76 $
package YourApp; use Catalyst qw(InflateMore ConfigLoader ...); # In your applications config file <appldir>__APPLDIR__</appldir> <binsdir>__BINSDIR__</binsdir> <libsdir>__LIBSDIR__</libsdir> <ctrldir>__appldir(var/etc)__</ctrldir> <dbasedir>__appldir(var/db)__</dbasedir> <logfile>__appldir(var/logs/server.log)__</logfile> <logsdir>__appldir(var/logs)__</logsdir> <root>__appldir(var/root)__</root> <rprtdir>__appldir(var/root/reports)__</rprtdir> <rundir>__appldir(var/run)__</rundir> <skindir>__appldir(var/root/skins)__</skindir> <tempdir>__appldir(var/tmp)__</tempdir> <vardir>__appldir(var)__</vardir>
If symbols like __MYSYMBOL__, __BINSDIR__, or __binsdir()__ are present in the application config they will be inflated to the appropriate directory paths if the coresponding lower case method name is defined in the inflation class
The Plugin::InflateMore attribute in the application config hash contains the name of the class whoose methods will do the actual inflating
Symbols should always use the forward slash as a path separator regardless of OS type, i.e. __appldir(var/logs)__
Create an instance of the class that will do the inflating
Override Catalyst::Plugin::ConfigLoader method. Will inflate any symbols matching the patterns __SYMBOL__ and __symbol( value )__
Call the appropriate method to get the base path and append any arguments. Returns a Path::Class object representing the arguments passed
None
There are no known incompatibilities in this module
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Peter Flanigan, <Support at RoxSoft.co.uk>
Larry Wall - For the Perl programming language
Copyright (c) 2008-2009 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
| Catalyst-Plugin-InflateMore documentation | Contained in the Catalyst-Plugin-InflateMore distribution. |
# @(#)$Id: InflateMore.pm 76 2009-07-29 17:00:18Z pjf $ package Catalyst::Plugin::InflateMore; use strict; use warnings; use namespace::autoclean; use version; our $VERSION = qv( sprintf '0.3.%d', q$Rev: 76 $ =~ /\d+/gmx ); use Catalyst::Utils; use Data::Visitor::Callback; use Path::Class; my $KEY = q(Plugin::InflateMore); my $SEP = q(/); sub setup { my ($self, @rest) = @_; $self->mk_classdata( q(_inflator) ); if (my $class = $self->config->{ $KEY }) { Catalyst::Utils::ensure_class_loaded( $class ); $self->_inflator( $class->new( $self ) ); } return $self->next::method( @rest ); } sub finalize_config { my $self = shift; my $v = Data::Visitor::Callback->new( plain_value => sub { return unless defined $_; s{ __(.+?)\((.+?)\)__ }{$self->_inflate_symbols( $1, $2 )}egmx; s{ __(.+?)__ }{$self->_inflate_symbols( $1, q() )}egmx; } ); $v->visit( $self->config ); return; } # Private method sub _inflate_symbols { my ($self, $attr, @rest) = @_; $attr = lc $attr; return $self->path_to( $rest[0] ) if ($attr eq q(home)); my @parts = ($self->_inflator->$attr(), split m{ $SEP }mx, $rest[0]); my $path = Path::Class::Dir->new ( @parts ); $path = Path::Class::File->new( @parts ) unless (-d $path); return $path->cleanup; } 1; __END__
# Local Variables: # mode: perl # tab-width: 3 # End: