wb to blogohell …

Par mc, 27 août 2010 17 h 33 min

bad mood last weeks so i escaped from blogosphere … I came back today and read a clever solution of the pascal’s triangle on Masak’s blog (http://use.perl.org/~masak/journal/40516?from=rss). I wrote code for years now, tried a lot of langages, stuck to perl5 because it’s the most featured one… and really wanted something better. Perl6 is really the kind of thing i expected for years (while coming to haskell).

So i read comments: « unreadable », « research language », « not for production » … comments close from those made by php or python users discovering $_ or the HOP …

bad mood again. log off …

navigate into koha code with vim

Par mc, 13 juillet 2010 10 h 11 min

this is an update for http://www.tinybox.net/2009/06/27/edit-koha-code-with-vim/


" if vim is in a koha root
if isdirectory('C4')
" Verb: ( n = navigate, o = open )
" Adjective: ( o = opac, i = intranet )
" Noon: ( t = template, n = include )

let g:koha_itmpl='koha-tmpl/intranet-tmpl/prog/en/modules' " intranet templates
let g:koha_iinc='koha-tmpl/intranet-tmpl/prog/en/includes' " intranet includes
let g:koha_otmpl='koha-tmpl/opac-tmpl/prog/en/modules' " opac templates
let g:koha_oinc='koha-tmpl/opac-tmpl/prog/en/includes' " opac includes

" so to open an intranet template, go on it with cursor and type ,oit

nnoremap ,nit :e =g:koha_itmpl
nmap ,oit ,nit/
nnoremap ,nii :e =g:koha_iinc
nmap ,oii ,nii/

nnoremap ,not :e =g:koha_otmpl
nmap ,oot ,not/
nnoremap ,noo :e =g:koha_oinc
nmap ,ooi ,ooi/

" add include in the path ... so gf works inside templates
exec 'set path+='.g:koha_iinc

endif

use Lazyness;

Par mc, 20 juin 2010 17 h 31 min

I enjoyed playing with my new Lazyness module. Book found a bug without even running the code afaik. It’s fixed and i added tests. I also added documentation and
and gited it.

I can also use TheForce now: based on Modern::Perl, it also exports Lazyness and List::AnyUtils.

lazyness in perl: so easy …

Par mc, 19 juin 2010 23 h 32 min

as some of you know, i’m a very enthousiastic haskell beginner and happy daily perl programmer. What i miss from haskell is:

- lazy arrays
- some prelude functions like takeWhile, while and filter (a lazy version of grep)

tonight, as i have to struggle one more time with very large CSV file, i realized how the while loop has become boring for me. I wrote a little haskell code.


positives = [0..]
is_even x = x `mod` 2 == 0
evens = filter is_even

main = mapM_ print
[ ("10 positives", take 10 positives)
, ("10 evens" , take 10 (evens positives) )
, ("evens < 10" , takeWhile (< 10) (evens positives) )
]

and tried to implement all my missings in perl.

* lazyness behavior can be implemented with closures
* so the subs take, takeWhile and filter use closures
* at the end of lazyness chain, i need a collect sub to get a real array

I started to code and it was quiet easy:


#! /usr/bin/perl
use 5.10.0;
use utf8;
use strict;
use warnings;

sub to_infinity_from {
my ($start) = @_;
sub { $start++ }
}

sub take {
my ( $want_more, $some ) = @_;
$want_more++;
sub { $want_more-- ? $some->() : undef }
}

sub takeWhile (&$) {
my ( $test, $list ) = @_;
sub {
local $_ = $list->();
defined or return undef;
$test->() ? $_ : undef;
}
}

sub filter (&$) {
my ( $test, $list ) = @_;
sub {
while ( defined ( local $_ = $list->() ) ) {
$test->() and return $_
}
undef;
}
}

sub collect ($) {
my ( $list ) = @_;
my @r;
while ( defined ( my $element = $list->() ) ) {
push @r,$element
}
@r;
}

for my $sequence
( [ "ten positives" => take 10, to_infinity_from(0) ]
, [ "ten evens" => take 10, filter { not( $_ % 2 ) } to_infinity_from(0) ]
, [ "evens less than 10" => takeWhile { $_ < 10 } filter { not( $_ % 2 ) } to_infinity_from(0) ]
) {
my ( $desc, $iterator ) = @$sequence;
say $desc;
while ( defined ( my $_ = $iterator->() ) ) { say $_ }
}

say $_ for "collector", collect take 10, to_infinity_from(0);

It worked! sooo easily! Now, a real live use case: I want a YAML::Dump of the first 10 adults of my csv file:


use Text::CSV;
use YAML;
use Lazyness ':all'; # collect, filter, take, takeWhile

( my $csv = Text::CSV->new({qw/ binary /})
or die Text::CSV->error_diag
)->column_names(qw/firstname lastname birthdate login /);

open my $fh,'users.csv' or die "$!";
say YAML::Dump [
collect take 10, filter {
$$_{birthdate} ~~ /(?\d{4})-/
and $+{year} < 1992
} sub { $csv->getline_hr($fh) }
];

Template::Declare::Quickly ?

Par mc, 15 juin 2010 20 h 54 min

Franck Cuny provided an experimental Dancer Template for Template::Declare. I realised that it wasn’t what i wanted so i spend some time tonight to find my way. I finally wrote Template::Declare::Quickly which isn’t a Dancer template at all:
just a syntaxic suggar on top of Template::Declare. Now i’m able to write:


package html;
use Template::Declare::Tags;

template page => sub {
my ( undef, $arg ) = @_;
html {
head {
title { "Dancer fart" }
}
body {
h1 { "prout" }
p { "welcome to $$arg{url}" }
}
}
};

package main;
use Template::Declare::Quickly
qw/ strict with dispatch_to / => [qw/ html /];

say html::show('page');

The code of Template::Declare::Quickly itself is very short. I’ll contact Sartak to be sure it doesn’t break some advanced use of Template::Declare.


package Template::Declare::Quickly;
use strict;
use warnings;

sub import {
shift;
my %args = @_;
if ( $args{dispatch_to} ) {
no strict 'refs';
for my $package ( @{ $args{dispatch_to} } ) {
push @{$package.'::ISA'}, 'Template::Declare'
}
}
Template::Declare->init(%args);
}

1;

the dancer meet astaire

Par mc, 15 juin 2010 9 h 12 min

During a perl6 workshop at FPW2010, Sukria and Martin Berends chatted about a perl6 port of Dancer. In my mind, it was already done (masak wrote a port of Rack called Web.pm and a port of Sinatra called Astaire long time ago) so I contacted Masak about the health of those code but masak admited Astaire was very experimental and did not gone far.

So masak and Tene joined #dancer, they are both perl6 programmers since 2 years AFAIK and would like to help. So we have 3 perl6 programmers interested by this Dancer port and all of them already played with web related projects. wow … perhaps it’s time to contact the mod_parrot author ;)

And yes … i promissed masak a post on dancer-users but everything was told on the chan yesterday.

FPW 2010

Par mc, 13 juin 2010 22 h 18 min

A chat with Laurent Dami who really helped me to understand some underlaying points of the discution about DBIx::Class::Direct. Thanks to him, i’m back to my initial idea (make the KiokuDB DBIx::Class backend work for us). Franck Cuny also told me about his satisfation related to the KiokuDB performances.

I also enjoy meeting Sukria and chatting with him. He already reported the Dancer related part on his blog so i won’t spoil here: just read it :)

Franck Cuny’s talk on Plack was an enlightened me about the Plack Middlewares. Plack isn’t just the implementation of PSGI. It also provide a very neat way to add plugins for the HTTP part of your web apps and frameworks. So implementing things at the plack level insteed of the Dancer one is a good way to share works between every perl frameworks. He made slides aboutDebug andStackTrace which provides very powerfull debugging informations. Definitely: i’ll use plackup now :)

I asked Franck about my Dancer-CGI-Wrapper. It already exists at the Plack level … i begun to read the code and it seems i can remove my repo :)

also a lot of chat with lot of people about perl6, haskell, the growth of functionnal programming, Calais by night, the rock’n'roll attitude of welsh eating, the french soccer team, the FPW’09 T-shirts … had a lot of fun thanks to all of you guys ( big up to Sebastien, Laurent and the sponsors linkfluence, dot and co, O’reilly, Linux mag, Ulco … Sebastien? did i missed someone? ;) ).

my bad step with ORMs

Par mc, 10 juin 2010 13 h 03 min

I didn’t work on Dancer-CGI this week as i only hacked on interesting things on my spare time. I hope i’ll come back on it when i’ll come back from FPW’10 (i’m about to go). So what’s up ?

First, I rewrote the patch about
named routes in dancer
: it’s now perl 5.8 crash free, tested and documented. Sukria started to merge it to his devel branch tonight.

Second, I begun to investigate on writing a business model on top of an ORM. I’m frustrated about that: i feel that the current ORMs failed to mix the ease of activerecord (ruby) and the power and extensibility of DBIx::Class (perl). I tried but it was an epic fail: everybody tried to discourage me to follow this way. As i understand the Laurent Dami’s answer: KiokuDB’s DBIx::Class backend would be a false trail too ?

I also seen an interesting talk (shout?) about the future of DBIx::Class. It’s a very clear review of the DBIx::Class good parts, bad parts and ideas to fix the bad parts. The future of DBIx::Class is awesome too! much closer than what i would like to use now and failed to imagine. Plus, Data::CapabilityBased reminds me the haskell classes which is one of the things love so much in this langage.

Dance, Koha, dance !

Par mc, 3 juin 2010 7 h 51 min

At the last Biblibre‘s CodeRun (beginning of May 2010), i wrote the first lines of a CGI wrapper for Dancer. The initial goal was to be able run legacy CGI.pm scripts written with the OO style on the top of Dancer

- with a minimal amount of changes (or even better: no change at all)
- every required changes must keep CGI compatibility.
- add the ability to share the bytecoding and the values of the loaded modules between http requests (as mod_perl does) to reduce time response and load average.
- make the CGI applications easier to debug (using dancer standalone server, the debug console and warning catch)

The proof of concept is to make Koha ILS run on top of Dancer. I wrote a kohadance.pl script for that.

I spent some time to work on it since, wrote some test files to make sure that i’m able to use %ENV, return correct http responses, correctly provide access to the http get and post parameters, correctly transmit the $query->header settings to Dancer, handle cookies, … . All the test suite runs successfully.

The results seems to be better than expected:
- the only code i had to change in koha is to replace the exit call by an safe_exit subroutine


sub psgi_env { any { /^psgi\./ } keys %ENV }
sub safe_exit {
if ( psgi_env ) { die 'psgi:exit' }
else { exit }
}

and make the CGI wrapper see the psgi:exit die as a normal termination. If anyone have an idea to trap ‘exit’ as it in the code: i’ll be very pleased to know.

- I’m now able to mix CGI.pm and Dancer code. So if you choose to break the CGI compatibility, you can port your script to a Dancer app step by step.

But there are still bugs! Speaking about koha: i can now log in and out the intranet, navigate on koha pages without experimenting some weird error or crash but (lot of)? stuff doesn’t work (for example: the main search doesn’t work). If you want to try yourself:

* git clone http://github.com/sukria/Dancer.git and git://github.com/eiro/Dancer-CGI-wrapper.git
* go to your koha root
* apply Dancer-CGI-wrapper/koha/0001-add-PSGI-ability.patch
* export KOHA_CONF
* run perl Dancer-CGI-wrapper/koha/kohadance.pl
* connect to http://localhost:3000 and http://localhost:3000/opac with your browser
* enjoy the kohadance « no search » opac ;)

Next steps are:

* use koha to go on debugging by identifying malfunctions, write tests and make them work
* make the package more CPAN ready. It’s already packaged thanks to module-starter but it is not a real Dancer plugin yet (bad namespaces, no use of Dancer::Plugin mechanics, no real documentation)

Help or feedback are welcome. please fork me on github :) .

libellés des erreurs systeme

Par mc, 27 mai 2010 13 h 28 min

passé sur #perlfr, cognominal++ nous montre comment avoir la liste des libéllés des erreurs systemes.

perl -wE ‘($!=$_),say « $_\t$! » for 1..132′

Panorama Theme by Themocracy