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;I should specify the fullpath of templates dir.
$C{TMPL_PATH} = '/path/to/view'; # ...
1;
MyApp/ - HOME directory. lib/ MyApp/ MyApp/Pages.pm view/ - template files. index.tt htdocs/ - static files. (images, JavaScript, CSS) logo.gif etc/ - config files.
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; } }
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; }