Monday, September 29, 2008

My 3rd CPAN module Today: Sphinx::Control

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

Sphinx::Control controls Sphinx searchd.

Thanks.

Labels:

two new CPAN modules

* Task::BeLike::FAYLAND

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

* Catalyst::Plugin::CHI

mix the CHI and Catalyst. :)

Labels: ,

Thursday, September 25, 2008

Beijing Perl Workshop on Nov 08, 2008

It is jointly organized with the postgresql china that means there will be some postgresql talks as well. We have also secured few sponsorships to fly Jesse Vincent and two other postgresql hackers to the workshop.

If you are planning a trip to beijing in the early November, send a email to conference[at]perlchina.org to register the workshop, or even better come give a talk(20,40 minutes or lighting talk)!

From http://use.perl.org/~Qiang/journal/37527

==============

I'm not sure if I can go there, but I want to!

Labels: ,

Friday, September 19, 2008

a busy release day today

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

2 new modules:
* Pod::Simple::Wiki::Googlecode
* Pod::From::GoogleWiki for http://use.perl.org/~schwern/journal/37476

and 1 refreshing module:
* Foorum

well, just enjoy!

Labels:

Thursday, September 18, 2008

Learn Moose 3: around

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 http://fayland.googlecode.com/svn/trunk/script/learn_moose/002_around.pl

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: http://search.cpan.org/~drolsky/Moose-0.57/lib/Moose/Cookbook/FAQ.pod#How_can_I_affect_the_values_in_@__using_before?

the example above is a case of 'deflate' as http://search.cpan.org/~drolsky/Moose-0.57/lib/Moose/Cookbook/FAQ.pod#How_can_I_get_Moose_to_inflate/deflate_values_in_the_accessor?

please read the FAQ and Cookbook for more details.

Thanks.

Labels:

Wednesday, September 17, 2008

jrock's git repos

http://git.jrock.us/?o=age

well, it has a lot of beautiful code.

git clone git://git.jrock.us/Ernst

Thanks.

Labels:

Monday, September 15, 2008

Foorum 0.2.2 release

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

Please download it from http://foorum.googlecode.com/files/Foorum-0.2.2.tar.gz

Thanks.

Labels:

Thursday, September 11, 2008

MooseX::TheSchwartz

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!

Labels: ,

Friday, September 05, 2008

Learn Moose 2: trigger

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': $!";
}
return;
}

# 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: http://fayland.googlecode.com/svn/trunk/script/learn_moose/001_attribute_trigger.pl

Thanks.

Labels:

Thursday, September 04, 2008

Learn Moose 1: subtype

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(1);
->verbose(0);
->verbose( sub {
my $msg = shift;
$msg =~ s/\s+$//;
print STDERR "[CUS] $msg\n";
} );
# then call ->debug depends on ->verbose.

final code is here:
http://fayland.googlecode.com/svn/trunk/script/learn_moose/007_subtype.pl

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

Labels: