two new CPAN modules

29 September 2008

* Task::BeLike::FAYLAND

OK, it's not so useful for u I think. just ignore it.

* Catalyst::Plugin::CHI

mix the CHI and Catalyst. :)

My 3rd CPAN module Today: Sphinx::Control

29 September 2008

the code and idea is directly from Lighttpd::Control and Nginx::Control.

Sphinx::Control controls Sphinx searchd.


a busy release day today

19 September 2008

I just kicked out 2 new modules and 1 refreshing module to CPAN.

2 new modules:
* Pod::Simple::Wiki::Googlecode
* Pod::From::GoogleWiki for

and 1 refreshing module:
* Foorum

well, just enjoy!

Learn Moose 3: around

18 September 2008

for example I want a shuffled list everytime when I can $t->shuffled_list;
I know I can use a sub to do the request. but with Moose, it's much more elegant.

the main code is like:
around 'shuffled_list' => sub {
my $next = shift;

my $ret = $next->(@_);
$ret = [ shuffle( @$ret ) ];

return $ret;

full source code can be found in

the output looks like:
1, 10, 6, 4, 2, 7, 9, 8, 3, 5
3, 4, 7, 2, 1, 9, 5, 6, 8, 10
Here we use 'around' instead of 'before' or 'after' because 'before' doesn't work according to this FAQ:[email protected]__using_before?

the example above is a case of 'deflate' as

please read the FAQ and Cookbook for more details.


Foorum 0.2.2 release

15 September 2008

0.2.2 Mon Sep 15 12:03:00
- use Catalyst::Plugin::PageCache '0.19' and key_maker
- split Model/ into ResultSet and remove it
- use 'MooseX::TheSchwartz' and 'TheSchwartz::Simple' to replace 'TheSchwartz'

Please download it from



11 September 2008

I just released a new version of MooseX::TheSchwartz today.

it's written on the way when I learn Moose. and most of the code is copied from TheSchwartz and TheSchwartz::Simple.
yet that's cool to write such things with Moose.

Moose rocks!

Learn Moose 2: trigger

05 September 2008

I want a scoreboard on MooseX::TheSchwartz.
so I defined one like "has 'scoreboard' => ( is => 'rw', isa => 'Str' );", but that's not what I want for all, I want more.
I want it to be a temp file related to $$ when I set it as 1 or 'on'.
I want I can custom a temp file for it.

I know I can write a method like the one in TheSchwartz. but with Moose, it's much more elegant as what u want!
has 'scoreboard'  => (
is => 'rw',
isa => 'Str',
trigger => sub {
my ($self, $dir) = @_;

return unless $dir;
# no endless loop when it's a file
if ($dir =~ /\/theschwartz\/scoreboard\./is) {
# get the real dir from $dir regardless a file
my (undef, $dir) = File::Spec->splitpath( $dir );
unless (-e $dir) {
mkdir($dir, 0755) or die "Can't create scoreboard directory '$dir': $!";

# They want the scoreboard but don't care where it goes
if (($dir eq '1') or ($dir eq 'on')) {
$dir = File::Spec->tmpdir();

$dir .= '/theschwartz';
unless (-e $dir) {
mkdir($dir, 0755) or die "Can't create scoreboard directory '$dir': $!";

$self->{scoreboard} = $dir."/scoreboard.$$";
now I have all I want.

just be careful, when u want to change itself in trigger like "$self->{scoreboard} = 'xxx'" or "$self->scoreboard('xxx');", u must make sure there isn't a endless loop since change itself will call trigger again.

test code can be found here:


Learn Moose 1: subtype

04 September 2008

finally I wrote my first Moose script.
mainly I want to write a MooseX::Schwartz if I have enough time.

Moose is very powerful.
I want a common function like set a flag to debug, besides that, we can define debug logger sub ourself.
something like:
->verbose( sub {
my $msg = shift;
$msg =~ s/\s+$//;
print STDERR "[CUS] $msg\n";
} );
# then call ->debug depends on ->verbose.

final code is here:

I'm not a Moose guru, but Moose sounds pretty exciting!

tip: one line force install CPAN module

07 July 2008

$> perl -MCPAN -e 'force("install","Foorum");'

that's it. Thanks.

3 day 3 release

17 June 2008

CPAN generally means responsibility. I released 3 Foorum distribution in the last 3 days.

CPAN means better document. so I tried to use DBICx::AutoDoc to create docs for Foorum::Schema. it's a bit different from the original method in DBICx::AutoDoc. I changed a bit to write pod into Schema files directly.

code are:(briefly)
my $ad = DBICx::AutoDoc->new(
schema => 'Foorum::Schema',
output => File::Spec->catdir($Bin, '..', '..', 'docs'),

# rewrite the Schema pm POD
use Template;

my $tt2 = Template->new( { INCLUDE_PATH => $ad->include_path, POST_CHOMP => 0, PRE_CHOMP => 0 } );
my $vars = $ad->get_vars;

# first get the lists of all Foorum::Schema pm files
my @sources = @{ $vars->{sources} };
foreach my $source (@sources) {
my $class = $source->{class}; # Foorum::Schema::User

# make file dir
my @parts_of_modules = split('::', $class);
$parts_of_modules[-1] .= '.pm';
my $file_dir = File::Spec->catfile( $Bin, '..', '..', 'lib', @parts_of_modules );

my $output;
$tt2->process('pod.html', { source => $source }, \$output)
|| die $tt2->error(), "\n";

# replace POD in real module
open(my $fh, '<', $file_dir);
local $/ = undef;
my $in = <$fh>;

my ($code, $pod) = split(/\n1;\n/, $in);
open(my $fh2, '>', $file_dir);
print $fh2 "$code\n1;\n__END__\n\n$output\n";

print "working on $class\n";
Full code can be found in