Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ikebe (2247)

  (email not shown publicly)

Journal of ikebe (2247)

Friday November 17, 2006
12:21 AM

Where am I?

[ #31636 ]

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';
# ...

I should specify the fullpath of templates dir.

this is a typical directory structure of mine.

MyApp/ - HOME directory.
  view/ - template files.
  htdocs/ - static files. (images, JavaScript, CSS)
  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\::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 = "$") =~ 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');

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.