tokuhirom's Journal
http://use.perl.org/~tokuhirom/journal/
tokuhirom's use Perl Journal
en-us
use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners.
2012-01-25T02:33:02+00:00
pudge
pudge@perl.org
Technology
hourly
1
1970-01-01T00:00+00:00
tokuhirom's Journal
http://use.perl.org/images/topics/useperl.gif
http://use.perl.org/~tokuhirom/journal/
-
I wrote Test::TCP
http://use.perl.org/~tokuhirom/journal/37210?from=rss
<p>I've wrote Test::TCP today.</p><p>If you write tests with Test::TCP, easy to write the test, that using TCP socket.</p><p>follow is example code.</p><p>
use warnings;<br>
use strict;</p><p>
package MyEchoServer;<br>
use IO::Socket::INET;</p><p>
sub new {<br>
my ($class, $port) = @_;</p><p>
my $sock = IO::Socket::INET->new(<br>
LocalPort => $port,<br>
LocalAddr => '127.0.0.1',<br>
Proto => 'tcp',<br>
Listen => 5,<br>
Type => SOCK_STREAM,<br>
) or die "Cannot open server socket: $!";<br>
bless { sock => $sock }, $class;<br>
}</p><p>
sub run {<br>
my $self = shift;</p><p>
while (my $remote = $self->{sock}->accept) {<br>
while (my $line = ) {<br>
print {$remote} $line;<br>
}<br>
}<br>
}</p><p>
package main;<br>
use strict;<br>
use warnings;<br>
use Test::More tests => 1;<br>
use Test::TCP;<br>
use IO::Socket::INET;</p><p>
test_tcp(<br>
client => sub {<br>
my $port = shift;<br>
my $sock = IO::Socket::INET->new(<br>
PeerPort => $port,<br>
PeerAddr => '127.0.0.1',<br>
Proto => 'tcp'<br>
) or die "Cannot open client socket: $!";<br>
print {$sock} "foo\n";<br>
my $res = ;<br>
is $res, "foo\n";<br>
},<br>
server => sub {<br>
my $port = shift;<br>
MyEchoServer->new($port)->run;<br>
},<br>
);</p><p>and repository is here:</p><p><a href="http://svn.coderepos.org/share/lang/perl/Test-TCP/trunk/lib/Test/TCP.pm">http://svn.coderepos.org/share/lang/perl/Test-TCP/trunk/lib/Test/TCP.pm</a></p>
tokuhirom
2008-08-17T06:30:13+00:00
journal
-
Perl5 VM Golf
http://use.perl.org/~tokuhirom/journal/36748?from=rss
<p>I've released Acme::PerlVMGolf.<br>This is new golf rule for perl hackers<nobr> <wbr></nobr>:)</p><p>PerlVMGolf's rule is very simple.follow is the rule:</p><p>
* write the code for the score<br>
* your score is sum of your op code number<br>
* short perl code is good</p><p>Are you right?</p><p>You can calcurate your score by Acme::PerlVMGolf(I've uploaded to CPAN now, and you can get from our svn repos http://svn.coderepos.org/share/lang/perl/Acme-PerlVMGolf/trunk/PerlVMGolf.xs).</p><p>
perl -MAcme::PerlVMGolf -e '0'<br>
hit: 177op<br>
hit: 174op<br>
hit: 178op<br>
Your perl is : 5.8.8<br>
Your score is : 529op</p><p>I give first challenge : how to implement 1000op?</p>
tokuhirom
2008-06-23T11:12:11+00:00
journal
-
Test::Snippet - Test interactive Perl examples
http://use.perl.org/~tokuhirom/journal/36664?from=rss
<tt>I've wrote Test::Snippet.<br>http://svn.coderepos.org/share/lang/perl/Test-Snippet/trunk/<br> <br><nobr> <wbr></nobr> This is a port of Python's doctest.<br>doctest is : http://docs.python.org/lib/module-doctest.html<br><br>1. use your module at re.pl(Devel::REPL)<br>2. copy and paste to pod<br>3. run tests.<br><br>that's all.<br><br>follow is example code:<br><br> your code here.<br><br> =head1 NAME<br><br> Acme::Test - testing acme<br><br> =head1 DESCRIPTION<br><br> blah blah blah<br><br> =begin test<br><br> $ 3+2<br> 5<br> $ [2,5,5,{foo => 'bar'}]<br> $ARRAY1 = [<br> 2,<br> ( 5 ) x 2,<br> { foo => 'bar' }<br> ];<br><br> =end test<br><br> =cut<br><br> something.. something..<br><br> =head1 SEE ALSO<br><br> ME!<br></tt>
tokuhirom
2008-06-12T04:05:50+00:00
journal
-
Moose::Role + overload
http://use.perl.org/~tokuhirom/journal/36582?from=rss
<tt>follow code does not works.<br><br> package MyApp::Role::Stringify;<br> use overload<br> q{""} => sub { shift->stringify }<br> <nobr> <wbr></nobr>;<br> requires 'stringify';<br><br> package MyApp;<br> with 'MyApp::Role::Stringify';<br> has dat ( is => 'ro', isa => 'Str' );<br> sub stringify { shift->dat }<br><br>because, the architecture of overload.pm is<br><br> export method named '()'<br> export method named '(""'<br><br>Moose::Role applies coderefs, that defined at Role.Exported methods are not import to applicant.<br><br>one way to resolve this problem is:<br><br> package MyApp::Role::Stringify;<br> use Moose::Role;<br> __PACKAGE__->meta->add_package_symbol('&()' => sub { }); # dummy<br> __PACKAGE__->meta->add_package_symbol('&(""' => sub { shift->stringify });<br><br>but, this is not so smart<nobr> <wbr></nobr>:( this is Hentai way(hentai means tricky in japanese)<br></tt>
tokuhirom
2008-06-04T02:20:03+00:00
journal
-
Moose talk in Japan
http://use.perl.org/~tokuhirom/journal/36570?from=rss
<tt>hakobe-san makes presentation about mooooooose at Kansai.pm.<br><br>slide is here: http://www.slideshare.net/hakobe/moose<br><br>moooooooooooooooooooose!</tt>
tokuhirom
2008-06-02T23:40:26+00:00
journal
-
MooseX::Plaggerize
http://use.perl.org/~tokuhirom/journal/36547?from=rss
<tt>### DESCRIPTION<br><br>I want to use Plagger style plugins architecture with Moose.Therefore, I created MooseX::Plaggerize!<br><br>svn repos is here: http://svn.coderepos.org/share/lang/perl/MooseX-Plaggerize/trunk/<br><br>### SYNOPSIS<br><br> # in main<br><br> my $c = Your::Context->new;<br> $c->load_config('config.yaml'); # feature of MooseX::Plaggerize::ConfigLoader<br> $c->load_plugin('HTMLFilter::StickyTime');<br> $c->load_plugin({module => 'HTMLFilter::DocRoot', config => { root => '/mobirc/' }});<br> $c->run();<br><br> package Your::Context;<br> use Moose;<br> with 'MooseX::Plaggerize', 'MooseX::Plaggerize::ConfigLoader';<br><br> sub run {<br> my $self = shift;<br><br> $self->run_hook('response_filter' => $args);<br> }<br><br> package Your::Plugin::HTMLFilter::StickyTime;<br> use strict;<br> use MooseX::Plaggerize::Plugin;<br><br> hook 'response_filter' => sub {<br> my ($self, $context, $args) = @_;<br> };<br><br>### CONCEPT<br><br> * Plugin architecture like Plagger<br> * Each plugin has own instance<br> * Each plugin can have own configuration<br><br>### What's difference with MooseX::Object::Pluggable?<br><br>yeah, I know MooseX::Object::Pluggable, ofcource.<br><br>MooseX::Object::Pluggable stands on Moose::Role and method modifiers.This is cool architecture.<br><br>But, this approach cannot use configuration like Plagger<nobr> <wbr></nobr>:(<br><br>therefore, I wrote MooseX::Plaggerize<nobr> <wbr></nobr>:)<br><br>###<nobr> <wbr></nobr>...<br><br>We would like to hear from you</tt>
tokuhirom
2008-05-30T02:32:58+00:00
journal
-
petit Moose movement in Japan
http://use.perl.org/~tokuhirom/journal/36330?from=rss
<tt>some Japanese perl mongers are interested to Moose, and reading the code, and some bloggers are writing 'Yet Another Moose Cookbook' in Japanese<nobr> <wbr></nobr>:-)<br><br>- my japanese blog: http://d.hatena.ne.jp/tokuhirom/<br>- yappo-san's : http://blog.yappo.jp/yappo/archives/000579.html<br>- hidek-san's: http://blog.hide-k.net/<br><br>and, a few days after, many Japanese perl mongers listen a nothingmuch's Moose talk in YAPC::Asia 2008 in Japan!!<br><br>Will Moose popular in Japan?</tt>
tokuhirom
2008-05-05T16:50:11+00:00
journal
-
scraping sibling nodes by Web::Scraper.
http://use.perl.org/~tokuhirom/journal/34958?from=rss
<tt>Web::Scraper is not good at some case. likes follow...<br><br> <div class="author">miyagawa</div><br> <div class="module">Web::Scraper</div><br> <div class="author">hanekomu</div><br> <div class="module">Dist-Joseki</div><br><br>This is not a tree structure.. hmm... Web::Scraper dependes on the tree structure, isn't it?<br><br>but, XPath is swiss army chainsaw.<br><br> scraper {<br> process '//div[@class="author"]', 'modules[]', scraper {<br> process '/.', 'author', 'TEXT';<br> process '/following-sibling::div[1][@class="module"]', 'title', 'TEXT';<br> }<br> };<br><br>but, this code is doesn't works.scraper cannot support this way.<br><br>If Web::Scraper supports this feature, you can be scraping from 'search.cpan.org', 'blog.livedoor.com', or many web sites more easily.<br><br>follow is the dirty and quick patch for this problem.<br>http://limilic.com/entry/c3qpikckc7f12jq3<br></tt>
tokuhirom
2007-11-23T02:05:19+00:00
journal
-
I wrote Test::ShellPerl
http://use.perl.org/~tokuhirom/journal/33817?from=rss
<tt>I wrote Test::ShellPerl.<br><br>This module likes doctest@python.<br><blockquote><br>The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown.<br></blockquote><br><br>Here's a small example module of doctest@python:<br><pre><br>"""<br>This is the "example" module.<br><br>>>> factorial(5)<br>120<br>"""<br>def factorial(n):<br> """Return the factorial of n, an exact integer >= 0.<br><br> If the result is small enough to fit in an int, return an int.<br> Else return a long.<br><br> >>> [factorial(n) for n in range(6)]<br> [1, 1, 2, 6, 24, 120]<br> >>> [factorial(long(n)) for n in range(6)]<br> [1, 1, 2, 6, 24, 120]<br> >>> factorial(30)<br> 265252859812191058636308480000000L<br> >>> factorial(30L)<br> 265252859812191058636308480000000L<br> >>> factorial(-1)<br> Traceback (most recent call last):<br> <nobr> <wbr></nobr>...<br> ValueError: n must be >= 0<br><br> Factorials of floats are OK, but the float must be an exact integer:<br> >>> factorial(30.1)<br> Traceback (most recent call last):<br> <nobr> <wbr></nobr>...<br> ValueError: n must be exact integer<br> >>> factorial(30.0)<br> 265252859812191058636308480000000L<br><br> It must also not be ridiculously large:<br> >>> factorial(1e100)<br> Traceback (most recent call last):<br> <nobr> <wbr></nobr>...<br> OverflowError: n too large<br> """<br><br> (snip the imprementation...<br></pre><br><br>Now, you can get this feature at Perl, with Shell::Perl.<br><br>Shell::Perl is cool interactive interface for Perl.You can use this interface for testing.like follow:<br><br><pre><br>=pod<br><br>=head1 DESCRIPTION<br><br>This is just a simple example module.<br><br>=begin test<br><br>pirl @> 3+2<br>5<br>pirl @><nobr> <wbr></nobr>:set out DD<br>pirl @> [2,5,5,{foo => 'bar'}]<br>@var = (<br> [<br> 2,<br> 5,<br> 5,<br> {<br> 'foo' => 'bar'<br> }<br> ]<br> );<br><br>=end test<br><br>=cut<br></pre><br>and run test then:<br><pre><br>ok 1 - 3+2<br>ok 2 - [2,5,5,{foo => 'bar'}]<br>1..2<br></pre><br><br>You can get the this module at my japanese blog.<br><br>http://d.hatena.ne.jp/tokuhirom/20070711/1184123829</tt>
tokuhirom
2007-07-16T11:26:05+00:00
journal
-
Gearman::Taskset::Async
http://use.perl.org/~tokuhirom/journal/33207?from=rss
<p>I wrote Gearman::Taskset::Async, the Gearman asynchronous taskset.</p><p>for example:<br>
use Gearman::Client;<br>
use Gearman::Taskset::Async;<br>
my $client = Gearman::Client->new(job_servers => ['127.0.0.1']);<br>
my $ts = $client->new_async_task_set;<br>
for (1..1000) {<br>
$ts->add_task("echo" => \$_, +{on_complete => sub {<br>
warn "COMPLETED";<br>
warn "@_";<br>
}, on_fail => sub {<br>
warn "FAILED";<br>
}});<br>
}<br>
$ts->run;</p><p>Gearman has asynchronous client(Gearman::Client::Async), is based on Danga::Socket.Danga::Socket imcompatible with mod_perl, because that uses class variables.</p><p>source code is here: <a href="http://back-paper.labs.mfac.jp/show?paper_rid=G6RBPTJKXq">Gearman::Taskset::Async</a></p><p>oops. It's just a Gearman::Taskset::BulkBlocRequest?</p>
tokuhirom
2007-05-06T10:56:51+00:00
journal
-
I released Gearman Client/Worker written in Python.
http://use.perl.org/~tokuhirom/journal/33206?from=rss
<p>Currently, gearman supports perl and ruby.I want to support Python!!Python is very sexy<nobr> <wbr></nobr>;-)</p><p>yeah, I wrote the Gearman Client/Worker in Python.</p><p>now, you can use:</p><p>
* Perl:Client → gearmand → Python:Worker<br>
* Python:Client → gearmand → Ruby:Worker</p><p>and more combination.</p><p>wow! It's wonderful(In Japanese: Yume-ga-hirogarain-Guuuu!!)</p><p>source code is here: <a href="http://back-paper.labs.mfac.jp/show?paper_rid=Izi4KERORy">Gearman Python Code.</a></p>
tokuhirom
2007-05-06T10:41:24+00:00
journal
-
Sledge::Plugin::Inflate::DateTime
http://use.perl.org/~tokuhirom/journal/31785?from=rss
<p>I think, generate DateTime instance from CGI.pm/Apache::Request is very frequent and very painful.</p><p>Yes, I wrote the Sledge::Plugin::Inflate::DateTime.</p><p>You just write the</p><blockquote><div><p> <tt>package Your::Pages;<br>use Sledge::Plguin::Inflate;<br>use Sledge::Plguin::Inflate::DateTime;<br>
<br>__PACKAGE__->add_inflate_rule_ymd('date'); </tt></p></div> </blockquote><p>then, you can inflate DateTime object easily.</p><blockquote><div><p> <tt>sub dispatch_foo {<br> my $self = shift;<br> $self->stash->{date} = $self->r->inflate('date');<br>}</tt></p></div> </blockquote><p>And, Sledge::Plguin::Inflate::DateTime and HTML::DateSelector go together!</p><blockquote><div><p> <tt>package Sledge::Plugin::Inflate::DateTime;<br>use strict;<br>use warnings;<br>use DateTime;<br>
<br>sub import {<br> my $pkg = caller(0);<br>
<br> no strict 'refs';<br> *{"$pkg\::add_inflate_rule_ymd"} = sub {<br> my ($class, $key, $datetime) = @_;<br> $datetime ||= 'DateTime';<br>
<br> $class->add_inflate_rule(<br> $key => sub {<br> my ( $self, ) = @_;<br> my %args;<br>
<br> $args{year} = $self->r->param("$key\_year");<br> $args{month} = $self->r->param("$key\_month");<br> $args{day} = $self->r->param("$key\_day");<br> if ( $args{year} && $args{month} && $args{day} ) {<br> return $datetime->new(%args);<br> }<br> return;<br> }<br> );<br> };<br>}<br>
<br>1;<br>__END__<br>
<br>=head1 SYSNOPSIS<br>
<br> package Your::Pages;<br> use Sledge::Plugin::Inflate::DateTime;<br>
<br> # simple way<br> __PACKAGE__->add_inflate_rule_ymd('from');<br>
<br> # you can use your customized DateTime class.<br> __PACKAGE__->add_inflate_rule_ymd('from' => 'Your::DateTime');</tt></p></div> </blockquote>
tokuhirom
2006-12-02T06:52:04+00:00
journal
-
I want to Sledge::Config->path_to.
http://use.perl.org/~tokuhirom/journal/31659?from=rss
<p>http://use.perl.org/~ikebe/journal/31636</p><p>I want to write tmpl_path with path_to in config.<br>Because, tmpl_path is a configuration variable.</p><blockquote><div><p> <tt>package Project::Config;<br>use strict;<br>use warnings;<br>use base qw/Sledge::Config/;<br>use Sledge::Plugin::PathTo;<br>use vars qw(%C);<br>*Config = \%C;<br>
<br>$C{TMPL_PATH} = path_to('view');<br>1;</tt></p></div> </blockquote><p>and, next version of Sledge::Config::YAML will supports<br>path_to, likes Catalyst::Plugin::ConfigLoader::YAML.Follw is<br>example configuration file:</p><blockquote><div><p> <tt>common:<br> tmpl_path: __path_to('view')__</tt></p></div> </blockquote><p>Yeah, that's so cool.</p>
tokuhirom
2006-11-19T14:30:33+00:00
journal
-
implementation of Sledge::Plugin.
http://use.perl.org/~tokuhirom/journal/31638?from=rss
<p>http://use.perl.org/~ikebe/journal/31589</p><p>here is implementation.</p><blockquote><div><p> <tt>package Sledge::Plugin;<br>use strict;<br>use warnings;<br>use base qw/Class::Data::Inheritable/;<br>
<br>__PACKAGE__->mk_classdata('methods');<br>__PACKAG E__->mk_classdata('hooks');<br>
<br>sub import {<br> my $class = shift;<br> my $pkg = caler(0);<br>
<br> # add methods<br> while (my ($name, $code) = each %{$class->methods || {}} ) {<br> no stirct 'refs';<br> *{"$pkg\::$name"} = $code;<br> }<br>
<br> # register hooks<br> $class->register_hooks( %{ $class->hooks || {} } );<br>}<br>
<br>sub add_methods {<br> my ($class, %d) = @_;<br>
<br> $class->methods(<br> {<br> %{ $class->methods || {} },<br> %d,<br> }<br> );<br>}<br>
<br>sub register_hooks {<br> my ($class, %d) = @_;<br>
<br> $class->hooks(<br> {<br> %{ $class->hooks || {} },<br> %d,<br> }<br> );<br>}<br>
<br>1;</tt></p></div> </blockquote>
tokuhirom
2006-11-17T07:25:50+00:00
journal
-
I released Sledge::Plugin::Pager 0.01 on CPAN.
http://use.perl.org/~tokuhirom/journal/31515?from=rss
<p>I wrote the Sledge::Plugin::Pager.</p><p>I want easy to write the paging, because every index page needs<br>paginate, in prgmatic web application.</p><p>A normal paginate dispatcher code is:</p><blockquote><div><p> <tt>sub dispatch_index {<br> my $self = shift;<br> $self->stash->{pager} = Your::Data::CD->pager(20, $self->r->param('page') || 1);<br> $self->stash->{cds} = $self->stash->{pager}->retrieve_all;<br>}</tt></p></div> </blockquote><p>follow is equevalent code with Sledge::Plugin::Pager.</p><blockquote><div><p> <tt>use Sledge::Plugin::Pager;<br>sub dispatch_index {<br> my $self = shift;<br> $self->pager('Your::Data::CD')->retrieve_all;<br>}</tt></p></div> </blockquote><p>Yeah, happy paging!</p>
tokuhirom
2006-11-05T15:32:34+00:00
journal
-
usage of sledge::view
http://use.perl.org/~tokuhirom/journal/31510?from=rss
<p>follow is an examle trigger code of Sledge::View.</p><blockquote><div><p> <tt>package Your::Pages::Base;<br>use strict;<br>use warnings;<br>use base qw/Sledge::Pages::Compat/;<br>use Switch;<br>use Jcode;<br>use Sledge::Plugin::PluginLoader;<br>__PACKAGE__->load_plugins(<br> qw/Stash View/<br>);<br>
<br>__PACKAGE__->add_trigger(<br> AFTER_DISPATCH => sub {<br> my $self = shift;<br>
<br> switch ($self->r->param('output')) {<br> case 'csv' {<br> $self->view('Sledge::View::CSV')->process;<br> $self->response->body(Jcode->new($self->response->body, 'euc')->sjis);<br> }<br> else {<br> $self->view('Template')->process;<br> }<br> }<br> }<br>);<br>
<br>1;</tt></p></div> </blockquote>
tokuhirom
2006-11-04T15:12:25+00:00
journal
-
Sledge::View 0.04 released
http://use.perl.org/~tokuhirom/journal/31498?from=rss
<p>I released Sledge::View 0.04 released.</p><p>This distribution includes the Sledge::View::CSV.</p><p>yeah, Japanese sales person often requires the CSV formatted files<nobr> <wbr></nobr>;-)</p><p>usage:</p><blockquote><div><p> <tt>package Your::Pages::Admin::Report;<br>use strict;<br>use warnings;<br>use base qw/Sledge::Pages::Compat/;<br>use Sledge::Plugin::View;<br>use Sledge::Plugin::Stash;<br>
<br>__PACKAGE__->add_trigger(<br> AFTER_DISPATCH => sub {<br> my $self = shift;<br> if ($self->r->param('output') eq 'csv') {<br> $self->view('CSV')->process;<br> }<br> else {<br> $self->view('Template')->process;<br> }<br> }<br>);<br>
<br>sub dispatch_report {<br> my $self = shift;<br> $self->stash->{row} = [[qw/a b/], [qw/c d/]];<br>}</tt></p></div> </blockquote><p>and, your template is:</p><blockquote><div><p> <tt><table><br> [% FOR row IN rows %]<br> <tr><br> [% FOR col IN row %]<br> <td>[% col %]</td><br> [% END %]<br> </tr><br> [% END %]<br></table></tt></p></div> </blockquote><p>if user access to '/admin/report/report' then get the html table report, and if access to '/admin/report/report?output=csv' then get the csv report.</p><p>yes, you can easy to change the view.</p>
tokuhirom
2006-11-03T14:41:29+00:00
journal
-
Sledge::Config to YAML::Load
http://use.perl.org/~tokuhirom/journal/31483?from=rss
<p>Long time ago, Sledge's config is written in codes, likes old version of Catalyst.</p><p>I want to write the config in YAML.YAML is cool, that is human readable and writable.</p><p>current style of Sledge::Config<nobr> <wbr></nobr>:</p><blockquote><div><p> <tt>package Proj::Config;<br>use strict;<br>use warnings;<br>use base qw(Sledge::Config Class::Singleton);<br>
<br>sub case_sensitive { 0 }<br>
<br>sub _new_instance {<br> my $class = shift;<br> unless (defined $ENV{SLEDGE_CONFIG_NAME}) {<br> do '/etc/proj-conf.pl' or warn $!;<br> }<br> $class->SUPER::new($ENV{SLEDGE_CONFIG_NAME});<br>}<br>
<br>1;<br>
<br>package Proj::Config::_common;<br>use strict;<br>use vars qw(%C);<br>*Config = \%C;<br>
<br>$C{TMPL_PATH} = '/path/to/tmpl_dir';<br>$C{COOKIE_NAME} = 'sledge_sid';<br>$C{COOKIE_PATH} = '/';<br>$C{COOKIE_DOMAIN} = undef;<br>
<br>1;<br>
<br>package Proj::Config::_development;<br>use strict;<br>use vars qw(%C);<br>*Config = \%C;<br>
<br>$C{DATASOURCE} = [ 'dbi:mysql:sledge','root', '' ];<br>
<br>1;<br>package Proj::Config::_product;<br>use strict;<br>use vars qw(%C);<br>*Config = \%C;<br>
<br>$C{DATASOURCE} = [ 'dbi:mysql:sledge;host=192.168.1.30','root', '' ];<br>
<br>1;</tt></p></div> </blockquote><p>If you use the Sledge::Config::YAML, written by precuredaisuki, you can write config by YAML.</p><blockquote><div><p> <tt>package Your::Config;<br>use basei qw(Sledge::Config::YAML Class::Singleton);<br>
<br>sub _new_instance {<br>
my $class = shift;<br>
<br>
$class->SUPER::new($ENV{SLEDGE_CONFIG_NAME}, $ENV{SLEDGE_CONFIG_FILE});<br>}<br>
<br>1;</tt></p></div> </blockquote><p>and, your yaml is:</p><blockquote><div><p> <tt>common:<br> tmpl_path:<nobr> <wbr></nobr>/path/to/tmpl_dir<br> cookie_name: sledge_sid<br> cookie_path:<nobr> <wbr></nobr>/<br> cookie_domain: ~<br>product:<br> datasource:<br> - dbi:mysql:sledge;host=192.168.1.30<br> - root<br> -<br>development:<br> datasource:<br> - dbi:mysql:sledge<br> - root<br> -</tt></p></div> </blockquote>
tokuhirom
2006-11-02T05:22:10+00:00
journal
-
Sledge::Plugin::URIFor
http://use.perl.org/~tokuhirom/journal/31470?from=rss
<p>I wrote the Sledge::Plugin::URIFor.This module provides $self->uri_for() method</p><blockquote><div><p> <tt>$self->uri_for('Proj::Pages::Foo' => 'add', {id => 35});<br># =><nobr> <wbr></nobr>/foo/add?id=35</tt></p></div> </blockquote><p>I complete wrote the code with tests.</p><p>But, Ikebe-san will release Sledge::Engine, that maybe includes url generating/parsing rule.</p><p>I'm waiting...</p><blockquote><div><p> <tt>package Sledge::Plugin::URIFor;<br>use strict;<br>use warnings;<br>our $VERSION = 0.01;<br>use Carp;<br>use Sledge::Utils;<br>use URI;<br>
<br>sub import {<br> my $pkg = caller(0);<br>
<br> no strict 'refs';<br> *{"$pkg\::uri_for"} = sub {<br> my $self = shift;<br>
<br> my @args = @_;<br>
<br> my $dir = Sledge::Utils::class2prefix($self);<br> my $page = '';<br> my $query = {};<br>
<br> for my $arg (@args) {<br> if (ref $arg eq 'HASH') { # query<br> $query = $arg;<br> } elsif ($arg =~<nobr> <wbr></nobr>/^[A-Z]/) { # module name<br> my $appclass = Sledge::Utils::class2appclass($self);<br> $arg = "${appclass}::Pages::$arg" unless $arg =~<nobr> <wbr></nobr>/^$appclass/;<br>
<br> $dir = Sledge::Utils::class2prefix($arg);<br> } elsif ($arg =~<nobr> <wbr></nobr>/^[a-z]/) { # page name<br> next if $arg eq 'index'; # through<br> $page = $arg;<br> } else {<br> die "invalid argument : $arg";<br> }<br> }<br>
<br> my $uri = URI->new($dir<nobr> <wbr></nobr>.($dir eq '/' ? '' : '/'). $page);<br> $uri->query_form($query);<br>
<br> return $uri->as_string;<br> };<br>}<br>
<br>1;</tt></p></div> </blockquote><p>and tests:</p><blockquote><div><p> <tt>use strict;<br>use warnings;<br>use Test::Base;<br>
<br>plan tests => 1*blocks;<br>
<br>filters(<br> {<br> input => [qw/yaml/],<br> }<br>);<br>
<br>run {<br> my $block = shift;<br>
<br> eval qq{<br> package @{[ $block->pages ]};<br> use Sledge::Plugin::URIFor;<br> sub new { bless {}, shift }<br> };<br> die $@ if $@;<br>
<br> my $page = $block->pages->new;<br> is( $page->uri_for( @{ $block->input } ), $block->expected,<br> $block->name );<br>};<br>
<br>__END__<br>
<br>=== simple<br>--- pages: Proj::Pages<br>--- input<br>- foo: bar<br>--- expected:<nobr> <wbr></nobr>/?foo=bar<br>
<br>=== deep<br>--- pages: Proj::Pages::Foo<br>--- input<br>- add<br>--- expected:<nobr> <wbr></nobr>/foo/add<br>
<br>=== complex<br>--- pages: Proj::Pages::Foo::Bar<br>--- input<br>- Bar::Baz<br>- edit<br>- foo: bar<br> bar: baz<br>--- expected:<nobr> <wbr></nobr>/bar/baz/edit?bar=baz&foo=bar<br>
<br>=== complex2<br>--- pages: Proj::Pages::Foo::Bar::Baz<br>--- input<br>- Proj::Pages::Bar::Baz<br>- edit<br>- foo: bar<br> bar: baz<br>--- expected:<nobr> <wbr></nobr>/bar/baz/edit?bar=baz&foo=bar</tt></p></div> </blockquote>
tokuhirom
2006-11-01T12:26:54+00:00
journal
-
Sledge::Plugin::CreateConfig
http://use.perl.org/~tokuhirom/journal/31464?from=rss
<p>I wrote the Sledge::Plugin::CreateConfig for Sledge2.0.This module generates crete_config method automatically.</p><blockquote><div><p> <tt>package Sledge::Plugin::CreateConfig;<br>use strict;<br>use warnings;<br>our $VERSION = 0.01;<br>use Carp;<br>use Sledge::Utils;<br>use UNIVERSAL::require;<br>
<br>sub import {<br> my $pkg = caller(0);<br>
<br> my $config_class = Sledge::Utils::class2appclass($pkg);<br> $config_class<nobr> <wbr></nobr>.= '::Config';<br>
<br> $config_class->use or die $@;<br>
<br> no strict 'refs';<br> *{"$pkg\::create_config"} = sub {<br> my $self = shift;<br> return $config_class->instance;<br> };<br>}<br>
<br>1;</tt></p></div> </blockquote><p>Old style Sledge code is likes follow:</p><blockquote><div><p> <tt>package Your::Pages;<br>use base qw/Sledge::Pages::Compat/;<br>
<br>use Your::Config;<br>sub create_config {<br> Your::Config->instance;<br>}</tt></p></div> </blockquote><p>I think, this is very verobse code.I want to write less codes.</p><p>If you use this plugin, you'll get a happy:</p><blockquote><div><p> <tt>package Your::Pages;<br>use base qw/Sledge::Pages::Compat/;<br>use Sledge::Plugin::CreateConfig;</tt></p></div> </blockquote><p>Now, This module is uped on CPAN.</p>
tokuhirom
2006-11-01T05:17:23+00:00
journal
-
load map to Sledge 2.0
http://use.perl.org/~tokuhirom/journal/31462?from=rss
follow is a list of load map to Sledge 2.0(draft).
<ul>
<li>wrap the Apache::Request</li><li>write the Sledge::Engine</li><li><ul>
<li>support mod_perl2</li><li>support fastcgi</li></ul></li><li>split Sledge::MobileGate, very thick wrapper, to many plugins</li><li>add Sledge::Plugin::MobileAgent</li><li>use Encode, internal char code change euc-jp to utf-8</li><li>add the Sledge::Plugin::FormValidator::Simple?</li></ul><p>
and more...</p>
tokuhirom
2006-11-01T00:12:04+00:00
journal
-
Sledge's components(draft)
http://use.perl.org/~tokuhirom/journal/31461?from=rss
follow is a list of Sledge's core components.
<dl>
<dt>Sledge::Pages</dt><dd>Controller</dd><dt>Sledge::Authorizer</dt><dd>authorization</dd><dt>Sledge::Session</dt><dd>session state(e.g. cookie)</dd><dt>Sledge::SessionManager</dt><dd>session storage(e.g. memcached, mysql)</dd><dt>Sledge::Template</dt><dd>template engine(e.g. TT2, HTML::Template)</dd><dt>Sledge::Config</dt><dd>config object</dd></dl><p>
I want to restructure the Sledge's components.</p>
tokuhirom
2006-11-01T00:07:57+00:00
journal
-
my first entry
http://use.perl.org/~tokuhirom/journal/31460?from=rss
I started the blogs in 'use Perl'.<br><br>By the day, I write the blog about Sledge, web application frame work written in Perl, on vox.com.<br>http://tokuhirom.vox.com/<br><br>miyagawa suggests 'Your blog should be write on use Perl;'.<br><br>Yes, I started the blogs on use Perl;.<br><br>Yeah, I'll write the some entries about Sledge.
tokuhirom
2006-10-31T23:41:36+00:00
others