MiniFramwork0.01公開

もっとこうしたほうがいいとか当然ありますので突っ込んでもらえたらうれしいです。
個人的には手を入れるべきだなぁと思ってる部分がまだ複数あります。

1.全体の構成
2.メソッドの種類と作り
3.PODの内容
4.エラー処理

etc...

ですかね。
まあ、とりあえず動くってことで公開します。


以下CGI::MiniFramworkです。


package CGI::MiniFramwork;
use strict;
use warnings;
our $VERSION = '0.01';
our $MODE;
our $TARGET;
sub new {
my($class,$self)=(shift,{@_});
bless($self,$class);
my $path_info = $ENV{'PATH_INFO'};
my ($dummy,$target,$mode) = split(/\//,$path_info);
$self->setup($target,$mode);
$self;
}
sub run {
my $self = shift;
my $obj = $self->get_object();
my $mode = $self->get_mode();
$self->print_header();
print $obj->$mode or die $!;
}
sub setup {
my $self = shift;
my $class = shift;
my $mode = shift;
if ( !$mode ) {
$mode = 'start';
}
$self->set_target($class);
$self->set_mode($mode);
}
sub get_object {
my $self = shift;
my $class = $self->get_target();
eval "require $class" or die $!;
my $obj = $class->new;
$obj;
}
sub set_target {
my $self = shift;
my $target = shift;
$TARGET = $target;
}
sub get_target {
$TARGET;
}
sub set_mode {
my $self = shift;
my $mode = shift;
$MODE = $mode;
}
sub get_mode {
$MODE;
}
sub print_header {
my $self = shift;
print "Content-Type: text/html;charset=Shift_JIS\n\n";
}
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
CGI::MiniFramwork - CGI framework of a minimum composition.
=head1 SYNOPSIS
### In "webapp.cgi"...
#! /usr/bin/perl
use strict;
use warnings;
use CGI::MiniFramwork;
use lib qw(.);
my $f = CGI::MiniFramwork->new();
$f->run();
### Dispatch Module...
package WebApp
....
sub new {
my($class,$self)=(shift,{@_});
bless($self,$class);
$self;
}
sub start {
my $self = shift;
return "Welcom CGI::MiniFramwork !!";
}
1;
=head1 DESCRIPTION
CGI::MiniFramwork is CGI framework of a minimum composition.
CGI::MiniFramwork doesn't depend on other modules excluding strict and warning.
You copies it onto an arbitrary place if you want to use this.
The preparation ends by this.
=head1 METHOD
=head2 new
=over 4
my $f = CGI::MiniFramwork->new();
Creates and returns new CGI::MiniFramwork object.
=back
=head2 run
=over 4
$f->run();
execute application.
=back
=head2 setup
=over 4
set up now target modules and now run mode.
=back
=head2 get_object
=over 4
get new target object.
=back
=head2 set_target
=over 4
set target module name.
=back
=head2 get_target
=over 4
get now target module name.
=back
=head2 set_mode
=over 4
set new run mode.
=back
=head2 get_mode
=over 4
get now run mode.
=back
=head2 print_header
=over 4
print HTTP Header
default Charset EUC_JP
You must overwrite if you want other charset.
=back
=head1 AUTHOR
Atsushi Kobayashi, E<lt>nekokak at users.sourceforge.jpE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2005 by Atsushi Kobayashi
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut

どうでしょうか?
配布形式でもつくってあるので後ほどここかWikiのサイトにアップしたいと思います。

感想なんかもいただけたら勉強になるのでうれしいです。
宜しくお願いします。m(_ _)m