Days20 intaractive shell

I like IRB which is intaractive shell in ruby.

Devel::REPL is perl intaractive shell.
Devel::REPLも便利 – だるろぐ跡地

$ cpanm Devel::REPL
Meny dependancy modules are installed.

How to use it:

$ use POSIX qw(strftime);
$ strftime ‘%c’, localtime((stat(‘README’))[9]);
2010年12月03日 01時58分04秒

How do I remember command history?
I press up button, but ‘^[[A’ is inputted.
I press left button, but ‘^[[D’ is inputted.


Days19 strftime

I checkout dad9d12, and cherr-pick 30d613a. This is strftime.

$ git checkout -b strftime dad9d12
$ git cherry-pick 30d613a

my $t = Time::Piece->strptime(
“$p->{year}/12/@{[sprintf(‘%02d’,$p->{day})]}”, ‘%Y/%m/%d’ ) ;

$vars->{update_at} = strftime ‘%c’, localtime((stat($file))[9]);

$ perldoc -f stat
9 mtime last modify time in seconds since the epoch

$ perldoc -f localtime
In scalar context, “localtime()” returns the ctime(3) value

So it appears real modify time. Not title date.

Days18 Xatena setting

I checkout 1bda857. And cherry-pick 6a1ee55.

I want to keep test code green. Because my clue is only test code.

all test is ok, But warning appears.

Odd number of elements in hash assignment at
/home/sane/perl5/perlbrew/perls/perl-5.12.2/lib/site_perl/5.12.2/Text/ line 44.

It is warning, so I don’t care.

Days17 Profile

I checkout 6efa6e1.

‘Add a profiling script’. I don’t know perl profiling way, But I execute it.

$ perl tool/
Can’t locate Devel/ in @INC (@INC contains:

/home/sane/perl5/perlbrew/perls/perl-5.12.2/lib/5.12.2 .) at
tool/ line 2.
BEGIN failed–compilation aborted at tool/ line 2.

$ perldoc Devel::NYTProf
No documentation found for “Devel::NYTProf”.

Devel::NYTProf is not exist.

$ cpanm Devel::NYTProf

$ perl tool/

$ ls -al
-rw-rw-r– 1 sane sane 1516917 2010-12-31 21:34 nytprof.out

What’s a large file!

$ less nytprof.out

This is binary. I don’t read it.

2008-07-17 – dann@webdev – dann’s portal

$ nytprofhtml
$ firefox ./nytprof/index.html

I see profile visually. But I don’t know where I need to see. ok.

Days16 recommends

I checkout aeff91c.

I find ‘recommends’ and ‘eval { require File::Spec::Memoized };’. recommends? What is this?

I search ‘$ perldoc recommends’ and google ‘perl recommends’. But I don’t get answer. Please tell me.

Days15 cache instance

I checkout ca7db7b.

This change store variable on hash.
my %xslate;

In subroutine local variable is not stored, in package
App::AdventCalendar local variable is stored, isn’t it?
Perhaps so.

Second, perl do syntax.
do has block.
my $tx = $xslate{$root} ||= do {

I read:
$ perldoc -f do

“do” returns the value of the last expression evaluated.

I understand it.

Days14 write patch

649883d is latest commit at p5-app-adventcalendar.
This failed test. Since e27a855, test have failed.
e27a855 added sample files, but route test depended on number of sample file.

Best way is each test are independent from others.
I wrote adhoc patch, Because all tests quickly become green is most important. My patch:

This brings that all test become green.

Days13 module version

How do I get installed cpan module? cpanminus and cpan is install command.
I like:
$ yum list
$ gem list
No doc mean no installed module. Boo.
Now I see:
$ pmvers URI::http
/home/sane/perl5/perlbrew/perls/perl-5.12.2/bin/pmvers: unknown version for module `URI::http’
Plack middleware module exist?
$ pmvers Plack::Middleware::Static
/home/sane/perl5/perlbrew/perls/perl-5.12.2/bin/pmvers: unknown version for module `Plack::Middleware::Static’
$ cpanm Plack::Middleware::Static
Plack::Middleware::Static is up to date. ()
$ pmvers Plack::Middleware::ContentLength
/home/sane/perl5/perlbrew/perls/perl-5.12.2/bin/pmvers: unknown version for module `Plack::Middleware::ContentLength’
$ cpanm Plack::Middleware::ContentLength
Plack::Middleware::ContentLength is up to date. ()
$ pmvers Plack::Middleware::Lint
/home/sane/perl5/perlbrew/perls/perl-5.12.2/bin/pmvers: unknown version for module `Plack::Middleware::Lint’
$ cpanm Plack::Middleware::Lint
Plack::Middleware::Lint is up to date. ()

$ perldoc Plack::Middleware::Static
This exists. muu.

Day12 Plack::Builder

I checkout df9efd2.
This use Plack::Builder.

Plack::Builder –
Description shows:
“The middleware you’re trying to use should use Plack::Middleware as a base class to use this DSL, inspired by Rack::Builder.”

So I understand Plack::Builder easily.
I can use Plack::Builder as a layer, and stack.

$ prove -lvr t/
t/00_compile.t ..
ok 1 – use App::AdventCalendar;
t/01_path.t …..
ok 1 – success case for list
Text::Xslate: Can’t locate object method “stringify” via package “URI::http” at /home/sane/work/p5-app-adventcalendar/lib/App/ line 95.
(assets/tmpl/entry.html:56:&main[48]) at t/01_path.t line 6
<a rel=”bookmark” href=”[% req.uri.stringify %]”>[% update_at %]</a>

… exception cought on accessor        … (assets/tmpl/entry.html:56:&main[48]) at t/01_path.t line 6
<a rel=”bookmark” href=”[% req.uri.stringify %]”>[% update_at %]</a>
ok 2 – success case for entry
ok 3 – entry file not found
ok 4 – data folder not found
ok 5 – invalid year format
ok 6 – invalid calendar name

All tests successful.
Files=2, Tests=7,  1 wallclock secs ( 0.03 usr  0.01 sys +  0.20 cusr  0.02 csys =  0.26 CPU)
Result: PASS
Is reallly successful? I feel this is doubt.
$ cpanm URI::http
But URI::http is updated.
And I think it doesn’t match naming rule. Perhaps I’m wrong.