Sledge::Plugin::CreateConfig

tokuhirom on 2006-11-01T05:17:23

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.


is it verbose?

miyagawa on 2006-11-01T06:43:21

I haven't thought that it's verbose since it's automatically generated. Hm, is create_config not part of the helper process?

Re:is it verbose?

tokuhirom on 2006-11-01T07:54:08

Ah, my company don't have a helper script orz. Please release, ikebe-san!!

Re:is it verbose?

tokuhirom on 2006-11-01T08:14:16

and ah, I'll write Module::Starter::Sledge(naming is ...).

Re:is it verbose?

miyagawa on 2006-11-01T08:29:27

No, I meant sledge-setup script which is in CVS.

Re:is it verbose?

tokuhirom on 2006-11-01T08:37:10

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.

Re:is it verbose?

miyagawa on 2006-11-01T08:49:02

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.

Re:is it verbose?

tokuhirom on 2006-11-01T09:11:45

Sorry, OK sure, that's no 'complex'.