Apache Tip: AddType

18 March 2009


see I setup a http://code.fayland.org/ for code review. then I want to show plain text for pl file like Makefile.PL
but by default, it's handled by perl. and it shows a 500 error in browser.

with the dreamhost support, I create a .htaccess like

RemoveHandler .pl .PL .t .html
AddType text/plain .pl .PL .t .html

and it works!

Thanks.

GitStore

13 March 2009


I just released another module http://search.cpan.org/dist/GitStore/ this morning.

GitStore - Git as versioned data store in Perl
use GitStore;

my $gs = GitStore->new('/path/to/repo');
$gs->store( 'users/obj.txt', $obj );
$gs->store( ['config', 'wiki.txt'], { hash_ref => 1 } );
$gs->commit();
$gs->store( 'yyy/xxx.log', 'Log me' );
$gs->discard();

# later or in another pl
my $val = $gs->get( 'user/obj.txt' ); # $val is the same as $obj
my $val = $gs->get( 'config/wiki.txt' ); # $val is { hashref => 1 } );
my $val = $gs->get( ['yyy', 'xxx.log' ] ); # $val is undef since discard

for now, it requires the Git::PurePerl master code. you must git clone it from http://github.com/acme/git-pureperl/tree/master and install into your local dir.

The git repo is http://github.com/fayland/perl-git-store/tree/master
welcome to fork it and submit any patches.

Thanks.

Net::GitHub

08 March 2009


I just released the new http://search.cpan.org/dist/Net-GitHub/.

it's basically a Perl interface to github.com which is the most popular git host in the world. perl5's source and perl6's rakudo source are there too.

I'm starting to like git and I put my code there too.
be inspired by Net::Google::Code, I created the http://github.com/fayland/perl-net-github/tree/master
everyone is welcome to fork it then pull request back to me.

Thanks very much, Enjoy.

note: github and Win32

07 March 2009


when author is unknown, you need set
E:\Fayland\perl-net-github>git config --global user.name "fayland"
E:\Fayland\perl-net-github>git config --global user.email [email protected]

just a note.

if more than one master, you need
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
from http://snippets.dzone.com/posts/show/5714

another note.

Perl tip: can returns coderef

23 February 2009


well, I just released the MooseX::Dumper today.

miyagawa on irc.perl.org #moose just told me that ->can() returns the coderef, so that I don't need to do follows:
        if ( $self->dumper_class->can($meth) ) {
my $class = $self->dumper_class;
my $val = eval "${class}::${meth}(\@_)"; # no critic
return $val;
}
Instead, just do:
        if ( my $dump_code = $self->dumper_class->can($meth) ) {
return $dump_code->(@_);
}
Yup, much more simpler and cleaner.

Thanks, miyagawa. 0.02 is on the way. :)

today's module: Scope::Guard

22 February 2009


Updated: Thanks for Eddy to point out the errors. :)

I have been very happy with Scope::Guard recently.

mainly the module can reduce the size of the code if you use it correctly.

for example, we have some piece of code like follows to deal with Sphinx error.
sub while_error {
my ( $ret ) = @_;

my $use_db = { use_db_please => 1 };

# 1, connection to {localhost}:{3312} failed: Connection refused
if ($ret->{error} =~ /Connection refused/is) {
faked_try_to_reconnect();
print STDERR "$ret->{error}\n";
return $use_db;
}
# 2, received zero-sized searchd response
elsif ($ret->{error} =~ /zero-sized searchd/) {
faked_try_to_re_search();
print STDERR "$ret->{error}\n";
return $use_db;
}
# 3, unknown local index
elsif ( $ret->{error} =~ /unknown local index/ ) {
faked_try_to_re_index();
print STDERR "$ret->{error}\n";
return $use_db;
}
# 4, recv: Connection reset by peer
elsif ( $ret->{error} =~ /Connection reset by peer/ ) {
print STDERR "$ret->{error}\n";
return $use_db;
}
return $ret;
}
OK, it's not so ugly.
but with Scope::Guard, we can rewrite it much more clear and small-size.
sub while_error {
my ( $ret ) = @_;

my $use_db = { use_db_please => 1 };

my $sg = Scope::Guard->new( sub {
print STDERR "$ret->{error}\n";
} );

# 1, connection to {localhost}:{3312} failed: Connection refused
if ($ret->{error} =~ /Connection refused/is) {
faked_try_to_reconnect();
return $use_db;
}
# 2, received zero-sized searchd response
elsif ($ret->{error} =~ /zero-sized searchd/) {
faked_try_to_re_search();
return $use_db;
}
# 3, unknown local index
elsif ( $ret->{error} =~ /unknown local index/ ) {
faked_try_to_re_index();
return $use_db;
}
# 4, recv: Connection reset by peer
elsif ( $ret->{error} =~ /Connection reset by peer/ ) {
return $use_db;
}

$sg->dismiss();

return $ret;
}
I'm not sure if you're happy with it or not, but I like it. :)
I had used it in http://code.fayland.org/fayland/CPAN/day_day_up/lib/DayDayUp/Backup.pm. that's just another example.

Thanks and Enjoy!

step by step: make daydayup as a WinXP service

22 February 2009


even it's very old, it's still very useful: http://www.perlguy.com/articles/nt_service.html

step 1, download the toolkit from http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

step 2, cmd: then
C:\Documents and Settings\Administrator>INSTSRV DayDayUp "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"

The service was successfuly added!

Make sure that you go into the Control Panel and use
the Services applet to change the Account Name and
Password that this newly installed service will use
for its Security Context.

step 3, cmd, regedit, then find "DayDayUp"
* Right click on the key and choose New, then Key. This will create what looks like a new folder. Name the new key Parameters.
* Right click on Parameters and select New, then String Value. In the space provided, type Application.
* Again, right click on Parameters and select New, then String Value. In the space provided, type AppParameters.
* Right click on Application and choose Modify, then type in the path to your Perl binary like C:\strawberry\perl\bin\perl.exe
* Next, right click on AppParameters and select Modify. type E:\Fayland\gsvn\CPAN\day_day_up\bin\day_day_up daemon 3001

OK, everything is done now. if you go Services, you'll find DayDayUp in list, and you can start it (it will be started whenever computer gets start)

Thanks.

CPAN Top 100

15 February 2009


Adam Kennedy just published his "The CPAN Top 100" today.

I just found that I take 11 places in "CPANTS Heavy 100". one is the Catalyst App Foorum and the others are Padre plugins. well, that's not a prize, I admire those listed in "CPANTS Volatile 100". :)

Thanks.

linux tool: logrotate

13 February 2009


logrotate is very useful tool in linux.

see I run sphinx searchd and it creates logs. it would become very large if I leave it alone.
and I have another cron script like theschwartz_worker.pl and it writes the debug info into file when I use $job->debug

those are very common situation. and with logrotate, it becomes simple.
place your files into /etc/logrotate.d/
like /etc/logrotate.d/searchd
/var/log/searchd/foorum.log {
weekly
rotate 5
compress
delaycompress
create 640 root root
postrotate
killall -SIGUSR1 searchd
endscript
}
like /etc/logrotate.d/theschwartz
/var/log/theschwartz.log {
weekly
rotate 10
compress
delaycompress
create 640 root root
}
After you write your conf, you can start test by:
$> logrotate -d /etc/logrotate.d/searchd
rotating pattern: /var/log/searchd/foorum.log weekly (5 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/searchd/foorum.log
log does not need rotating
not running postrotate script, since no logs were rotated

google around to find more details. or just man logrotate.

Thanks.

mod_autoindex Options on irclog.foorumbbs

09 February 2009


well, after a bit search, I'm very happy to see http://irclog.foorumbbs.com/ is behaving like what I want now.

no big magic, just read through http://httpd.apache.org/docs/2.2/mod/mod_autoindex.html
then create a .htaccess in my dreamhost server.
IndexOrderDefault Descending Date
IndexOptions +FancyIndexing +FoldersFirst +NameWidth=*
just a note. :)