Sledge based application does not know "Where am I?".
so, Sledge configurations are slightly verbose.
package MyApp::Config::_common;
use strict;
use vars qw(%C);
*Config = \%C;
$C{TMPL_PATH} = '/path/to/view';
#...
1;
I should specify the fullpath of templates dir.
this is a typical directory structure of mine.
MyApp/ - HOME directory.
lib/
MyApp/
MyApp/Pages.pm
view/ - template files.
index.tt
htdocs/ - static files. (images, JavaScript, CSS)
logo.gif
etc/ - config files.
Catalyst like path_to impl.
package Sledge::Plugin::PathTo;
use strict;
use Path::Class;
sub import {
my $pkg = caller(0);
no strict 'refs';
$pkg->mk_classdata(qw(home));
$pkg->home(find_home($pkg));
*{"$pkg\::path_to"} = sub {
my ( $self, @path ) = @_;
my $path = dir( $self->home, @path );
if ( -d $path ) {
return $path;
}
else {
return file( $self->home, @path );
}
};
}
sub find_home {
my $class = shift;
(my $file = "$class.pm") =~ s{::}{/}g;
if ( my $inc_entry = $INC{$file} ) {
my $path = file($inc_entry)->absolute->cleanup->stringify;
$path =~ s/$file$//;
my $home = dir($path);
$home = $home->parent while $home =~/(b?lib|site_perl)$/;
return $home->stringify if -d $home;
}
}
yeah, I do not have to write the fullpath in config.
package MyApp::Pages;
use strict;
use Sledge::Pages::Compat;
use Sledge::Plugin::PathTo;
sub create_config {
my $self = shift;
my $config = MyApp::Config->instance;
$config->{tmpl_path} = $self->path_to('view');
$config;
}
Where am I? 0 Comments More | Login | Reply /