Category: Perl

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.

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 :) .

perl completion in vim: i finally try it

Par mc, 10 novembre 2009 1 h 20 min

I was waiting a long time to have a perl completion system in vim. I waited because i’m lazy and because i thought someone more skilled than me will finally handle that. I don’t know about PPI or other perl parsing technics and i expected the completion to be really smart.

Time passed and there is no such thing in the place. I used ctags completion but it’s very borring to see packages names of your whole @INC when you try to complete a method name.

Still waiting for something really smart, i spent 2 evenings to write a ‘not so smart completion’ … my first use cases surprised me is it seems to be smart enought to go on waiting for another long time :-) .

I’ll try a daily use starting tomorrow and will feedback in a week. If you can’t wait for testing, debugging, feedback:

the perlcfu git repo

perl onliners, vim and iso2709

Par mc, 12 octobre 2009 12 h 47 min

tips of this post are cool even if you don’t deal with iso2709.

i wrote a post to explain how sweet it can be to use vim to deal with stdout. Now i want to see the content of a iso2709 file.

as the record separator of iso2709 is « \x1d » but vim

- can’t define a separator different from the standard ones ( combining « \r » and « \n » )
- is very bad to manage very long lines (what an iso2709 file actually is for it)

to navigate in your file, it would be cool to append a « \n » just after « \1xe » (field separator) but with no side effect on the original file. Perl do it easily by mixing -E -0 and -n.

-e flag is to execute perl code ( -E to include perl 5.10 features )

perl -E 'say "hello"'

-n make this code executed for each lines of a read file ( $_ : line content, $. : line number )

cat /etc/hosts
# can be written
perl -nEprint /etc/hosts
grep -n localhost /etc/hosts
# can be written
perl -nE '/localhost/ and print "$. : $_"' /etc/hosts

-0 can change the record separator so

perl -0x1e -nEsay biblio.iso2709

read the file field by field ( -0x1xe ) and append a « \n » (say does it) at the end of each one. Pipe it to vi and you’ll have a fast way to walk through your file.

perl -0x1e -nEsay biblio.iso2709  | vim -

also, set dy (display) to uhex to see the hex codes of the separators ( « \x1d » for the record, « \x1e » for field, « \x1f » for subfield)

:set dy=uhex

also note that perl -n accepts some sed style range

# just see the records 10 to 23
perl -0x1d -nE'  10..23 and print' biblio.iso2709  | vim -
# just see from record 10 to the record that contains the word 'plan9'
perl -0x1d -nE'  10../plan9/ and print' biblio.iso2709  | vim -

and the awk style BEGIN and END blocks

# count the number of records
perl -0x1d -nE 'END { say $. }' biblio.iso2709

Panorama Theme by Themocracy