cpanmeta fav++ modules helping you! / sorry this is not spam

I like CPANMeta fav++ this is nice than cpanratings.perl.org.

my opinion the "like" rating is better and well working than "5 stars" rating because 5 stars system often is used to report bug (sad.. but true).

so today I wrote small cpanmeta-fav.pl script inspired by Dagolden's this entry.

I just fav++ed too many modules help me to get things done.

perl and cpan ec…

using Dancer as WAF ::Utils

after PSGI, CPAN has a lot of parts to build Web Application Framework. It is easy making WAF yourself without uploaded WAF.

I think WAF uploaded on CPAN are just to provide a style.

Catalyst provides router system using method attribute. Web::Simple uses proto. Mojo provides WAF OO, Mojolicious::Lite provides some keyword for routing. Dancer provides many keywords. bla bla...

I didnt like any styles for my current project, but didnot want to make WAF from scratch.

So. now Im trying to use Dancer. I dont need full keywords. but "every feature is from keyword" style means Dancer looks like ::Util modules.

For example, you may use only the Dancer parts you need in this way.

package My::Web;
use strict;
use Dancer qw/:syntax config/;
use Dancer::Config;

sub new {
    my ($class, %args) = @_;
    Dancer::set($_ => $args{$_}) for keys %args; # should set "appdir"
    Dancer::Config->load;
    my $self = $instance = bless { }, $class;
}

sub psgi_app {
    my ($self) = @_;
    for my $map (list $self->config->{routing}) {
        my $class  = load($map->{class});

        Dancer::any($map->{method}, $map->{path} => sub {
            my $controller = $class->new(app => $self);
            my $method     = lc Dancer::request()->method;
            $controller->$method();
        });
    }

    return Dancer->start; # psgi app
}

Of course I know this is not an official. but this work. and shold work.

If you didnt like any styles on CPAN WAF but didnot want to make WAF from scratch, Dancer may be useful as providing WAF parts.

I know that Dancer v2 is in development, I hope v2 is also such a good WAF utility.

Excuse me for poor entry Im in a hurry to go Halloween party :)

perl5.10, give back our $_

perl5.10 added given keyword. very nice.

However, given("foo") does my $_ = "foo"(lexical $_) implicitly. This means it does not work code using local $_ in given block. like this:

use 5.010;

sub foo(&$) {
    my ($code, $value) = @_;
    local $_ = $value;
    $code->();
}

foo { print $_ } "foo"; # => "foo"

given ('xxx') {
    foo { print $_ } "foo"; # => "xxx"
}

this occurs even List::Util.

use 5.010;
use List::Util qw/first/;

given ('xxx') {
    my $test = first { $_ eq 'xxx' } qw/ bar baz /;
    # $test => bar
}

or Try::Tiny (POD described this point.)

use Try::Tiny;

given ('xxx') {

    try {
        die "error";
    } catch {
        warn $_; # => "xxx"
    }

}

I think we can avoid unnecessary problems by given() make local $_ instead of lexical $_.

What do you think?

of course, It may be there is the purpose of lexical scope that I have not understand.(I dont read all p5p logs.)

and, We can use global $_ this way even inside lexical $_ scope.

given ('xxx') {
    foo { our $_; print $_ } "foo"; # => "foo"
}

or

given ('xxx') {
    foo { print $::_ } "foo"; # => "foo"
}