I wrote the Sledge::Plugin::AutoTmplDirname.
If you use this module, you don't need to set tmpl_dirname every Pages class.
Laziness++.
package Sledge::Plugin::AutoTmplDirname;
use strict;
use warnings;
our $VERSION = 0.01;
use Carp;
use Sledge::Utils;sub import {
my $pkg = caller(0);no strict 'refs'; ## no critic
*{"$pkg\::tmpl_dirname"} = sub {
my $self = shift;
return Sledge::Utils::class2prefix($self);
};
}1;
__END__
=head1 NAME
Sledge::Plugin::AutoTmplDirname - auto generate the template directory name
=head1 SYNOPSIS
package Your::Pages;
use Sledge::Plugin::AutoTmplDirname;# generate the tmpl_dirname method automaticaly.
=head1 DESCRIPTION
This module generates tmpl_dirname method.
Laziness++
=head1 BUGS AND LIMITATIONS
No bugs have been reported.
=head1 AUTHOR
Tokuhiro Matsuno C<< <tokuhiro __at__ mobilefactory.jp> >>
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2006, Tokuhiro Matsuno C<< <tokuhiro __at__ mobilefactory.jp> >>. All rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.
I have a bad memory.I often forget to write 'enctype="multipart/form-data"'.
I wrote the HTML::FillEncType, insert 'enctype="multipart/form-data"' automatically.
package HTML::FillEncType;
use strict;
use base qw(HTML::Parser);
use URI;
use vars qw($VERSION);$VERSION = '0.12';
sub new {
my $class = shift;my $self = bless { }, $class;
$self->SUPER::init;
$self->boolean_attribute_value('__BOOLEAN__');
$self;
}sub fill_enc_type {
my ($self, $args) = @_;$self->{output} = "";
if ($args->{file}) {
$self->parse_file($args->{file});
}
elsif ($args->{scalarref}) {
$self->parse(${$args->{scalarref}});
}
elsif ($args->{arrayref}) {
foreach my $line(@{$args->{arrayref}}) {
$self->parse($line);
}
}return $self->{output};
}sub output {
my $self = shift;
return $self->{output};
}sub start {
my ($self, $tagname, $attr, $attrseq, $orig) = @_;if ($tagname ne 'form') {
$self->{output} .= $orig;
return;
}
else {
$self->{output} .= qq{<$tagname enctype="multipart/form-data"};
for my $key (@$attrseq) {
if ($attr->{$key} eq '__BOOLEAN__') {
$self->{output} .= " $key";
}
else {
$self->{output} .= sprintf(
qq{ $key="%s"},
$self->escapeHTML($attr->{$key})
);
}
}
$self->{output} .= ">";return;
}
}sub process {
my($self, $text, $orig) = @_;
$self->{output} .= $orig;
}sub end {
my ($self, $tagname, $orig) = @_;
$self->{output} .= $orig;
}sub text {
my ($self, $orig) = @_;
$self->{output} .= $orig;
}sub comment {
my ($self, $orig) = @_;
$self->{output} .= qq/<!--$orig-->/;
}sub declaration {
my ($self, $orig) = @_;
$self->{output} .= qq/<!$orig>/;
}sub _croak {
require Carp;
Carp::croak(@_);
}sub escapeHTML {
my $self = shift;
my $text = shift;
$text =~ s/&/&/g;
$text =~ s/"/"/g;
$text =~ s/</</g;
$text =~ s/>/>/g;
return $text;
}1;
__END__
=head1 SYNOPSISmy $enc = HTML::FillEncType->new;
my $html = '<html><form method="get"><input type="text" name="hoge" /></form></html>';
print $enc->fill_enc_type({ scalarref => \$html });=head1 NOTES
many code from HTML::StickyQuery.
Thanks to id:ikebe.
uploaded!!
and, I'll upload the Sledge::Plugin::Laziness tomorrow.
Back in the day, this module is in the MoFedge.But, I hope to use this module by all Sledge users.
I wrote the Sledge::Plugin::Laziness.
laziness++
package Sledge::Plugin::Laziness;
use strict;
use warnings;
use Sledge::Utils;
use UNIVERSAL::require;sub imoprt {
my $pkg = caller(0);*{"$pkg\::tmpl_dirname"} = sub {
my $self = shift;
return Sledge::Utils::class2prefix($self);
};*{"$pkg\::create_config"} = sub {
my $self = shift;my $config_class = Sledge::Utils::class2appclass($self);
$config_class .= '::Config';$config_class->use or die $@;
return $config_class->new($self);
};
}1;
package Sledge::Utils;
use strict;
use warnings;
use String::CamelCase;sub class2prefix {
my $class = shift;$page_name = ref $self || $self;
$page_name =~ s!.+Pages!!g;
$page_name =~ s/^::(Index|Root)$/::/g;
return join '/', map { decamelize($_) } split /::/, $page_name;
}sub class2appclass {
my $class = shift;my $proto = ref $class || $class;
$proto =~ s/::Pages.+$//;
return $proto;
}
Directory layout for Sledge at Mobile Factory.
./project
./site_perl/- *.pm
Projec/Pages.pm
./project/template - template file
./project/htdocs - static files
./project/script/./project/script/cron/
./project/script/temporary/2006/10/hoge.pl./t - test scripts
I hate this.
Yeah, I released Sledge::View on CPAN.
You can use the alpha version of Sledge::View.
http://search.cpan.org/~tokuhirom/Sledge-View-0.01/
and, Sledge::View's svn repository is here: http://code.mfac.jp/svn/CPAN/tokuhirom/Sledge-View/
Yeah. I wrote the prototype of the Sledge::View.
http://code.mfac.jp/trac/browser/CPAN/tokuhirom/Sledge-View/
This module constructed by 4 modules.
- Sledge::Plugin::View
- change Sledge::Pages::Base...
- Sledge::Response
- HTTP Response object
- Sledge::View
- abstract base class for Sledge::View::*
- Sledge::View::Template
- compatibility for Sledge::Pages::Base->(make_content|output_content)
Now this modules are beta.But, I want to release on CPAN at this week, with more tests.
package Proj::Pages;
sub create_view { Proj::View::TT->new(shift) }
sub dispatch_index {
my $self = shift;
$self->stash->{cd} = Proj::Data::CD->retrieve($self->r->param('cd_id'));
}
sub dispatch_mmm {
my $self = shift;
$self->stash->{cd} = Proj::Data::CD->retrieve($self->r->param('cd_id'));
$self->view('TT')->process(); # $self->final(1)
}
I wrote the prototype of Sledge::Plugin::View.
package Sledge::Plugin::View;
use strict;
use warnings;
our $VERSION = 0.01;
use Carp;sub import {
my $pkg = caller(0);*{"$pkg\::make_content"} = sub {
my $self = shift;
croak "You can't use make_content method, because $self uses Sledge::Plugin::View.";
};*{"$pkg\::output_content"} = sub {
my $self = shift;my $view = $self->create_view;
$view->process($self);
};*{"$pkg\::create_view"} = sub { Sledge::Exception::AbstractMethod->throw };
}1;
__END__=head1 TODO
change view module by dispatcher.
and the Sledge::View.
package Sledge::View;
use strict;
use warnings;
use Sledge::Exceptions;sub process {
Sledge::Exception::AbstractMethod->throw
}1;
I want to use Sledge::View.
Sledge::View is composed by Sledge::View and Sledge::Plugin::View.
Sledge::View is abstract parent class of Sledge::View::*(e.g. Sledge::View::TT)
Sledge::Plugin::View extends Sledge::Pages::Base for use Sledge::View.
- *Sledge::Pages::Base::make_content = sub { Sledge::Exception::Obsolete->throw }
- *{"$pkg\::output_content"} = sub { .. }
- $self->view('QRCode')
convert request's charset should convert in AFTER_INIT phase(Sledge::Plugin::ConvertRequestCharset ?).
output_filter is...