Stories
Slash Boxes
Comments
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 ]

tokuhirom (7396)

tokuhirom
  (email not shown publicly)
http://d.hatena.ne.jp/tokuhirom/

Journal of tokuhirom (7396)

Wednesday November 01, 2006
12:17 AM

Sledge::Plugin::CreateConfig

[ #31464 ]

I wrote the Sledge::Plugin::CreateConfig for Sledge2.0.This module generates crete_config method automatically.

package Sledge::Plugin::CreateConfig;
use strict;
use warnings;
our $VERSION = 0.01;
use Carp;
use Sledge::Utils;
use UNIVERSAL::require;
 
sub import {
    my $pkg = caller(0);
 
    my $config_class = Sledge::Utils::class2appclass($pkg);
    $config_class .= '::Config';
 
    $config_class->use or die $@;
 
    no strict 'refs';
    *{"$pkg\::create_config"} = sub {
        my $self = shift;
        return $config_class->instance;
    };
}
 
1;

Old style Sledge code is likes follow:

package Your::Pages;
use base qw/Sledge::Pages::Compat/;
 
use Your::Config;
sub create_config {
  Your::Config->instance;
}

I think, this is very verobse code.I want to write less codes.

If you use this plugin, you'll get a happy:

package Your::Pages;
use base qw/Sledge::Pages::Compat/;
use Sledge::Plugin::CreateConfig;

Now, This module is uped on CPAN.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I haven't thought that it's verbose since it's automatically generated. Hm, is create_config not part of the helper process?
    • Ah, my company don't have a helper script orz. Please release, ikebe-san!!
      • and ah, I'll write Module::Starter::Sledge(naming is ...).
      • No, I meant sledge-setup script which is in CVS.
        • Ah, I don't use this. and, My first impression of Sledge, Proj::Pages::Base is too complex. Proj::Pages::Foo contains many follow codes.
          use Sledge::Foo::Bar;
          sub create_foo {
            my $self;
            Sledge::Foo::Bar->new($self);
          }
          I want to short that.
          • I agree it's verbose but don't agree it's "complex." I didn't care that much since it could be auto-generated and the code is still there if you want to override the behavior, say, to replace MySQL with PgSQL for session storage.