Dancer: Getting to Hello World

R Geoffrey Avery will be giving a talk at YAPC::NA 2012 that he describes as:

When attempting to learn Dancer I ran into the problem that all the documentation started from “Here is a ‘Hello World’ script”.  But that was assuming many things were set up and configured and that just was not true, at least not on my server.

This is a collection of what I learned.

[From the YAPC::NA Blog.]

Serving Files with Dancer::Plugin::DirectoryView and Dancer::Plugin::Auth::Htpasswd

A while ago I was converting a simple PHP website to Dancer, and moving it from being deployed on Apache to Starman. There wasn't a lot of code, so rewriting went quickly -- but, the site used a few specific features of Apache, namely directory indexes (courtesy of mod_autoindex) to allow user access to directories/files on the server, and htpasswd files to password-protect some of those directories.

I could just deploy the new Dancer website on Apache and keep using those goodies, but I thought that it would be nice if Dancer itself provided similar features. So, I created two plugins that do just that: Dancer::Plugin::DirectoryView and Dancer::Plugin::Auth::Htpasswd. Let me now show you how to use them.

CPAN, my first time.

It was not that difficult getting my first distribution released on CPAN. But getting rid of the rough edges meant spending time with my favourite search engine and on IRC.

My code is hosted on github and I decided to let Dist::Zilla handle most of the work associated with releasing. Oh and I already had a PAUSE account so I could start right away.

Using Dist::Zilla turned out to be easy. Just install and after following the tutorial for some minutes I took my new distribution for a first spin.

dzil test
to make sure everything works. (Btw. I finally got around to writing tests, something I have avoided for far too long.)
dzil build
so I can have a look at the final result
dzil release
publish the first development release.

Try the new perldoc

I took over maintenance of Pod-Perldoc, and with the help of a lot of people, I'm ready to merge it into the perl sources. There aren't major new features or a change in structure. I applied a lot of patches. Pod-Perldoc-3.15_12 is on CPAN so you can play with it. This next release fixes 15 old RT tickets, some of them major problems but most of them quick fixes that I merely needed to apply. This week is a good time to test it as the perl sources have a contentious code freeze before Perl 5.16.

The biggest change gets rid of pod2man, which perldoc was using before it turned into the Pod::Man module. Now that it's a module, we can just call it directly. I think that mostly works now, but please test it. See if you can read all of perlfunc.

The Perl Foundation Review 2011 - 2012

Karen Pauley will be giving a talk at YAPC::NA 2012 she describes as:

Over the past year The Perl Foundation has continued to work on its goal of advancing Perl and supporting the community. This talk will provide a review of our recent successes and failures, and take a brief look at the plans for the year ahead.

[From the YAPC::NA Blog.]

What does CATALYST_DEBUG do?

Introduction

I used to think that CATALYST_DEBUG was an all-reaching magical environment variable that somehow affected the ‘Come back Later’ screen as well as what messages were output via $c->log->...().

I’ve educated myself since then but I’ve always thought it would be an interesting exercise explicitly exploring and documenting the various behaviour under different conditions.

The Code

Code for this example can be found in the catalyst_debug branch.

After each change we run ./script/demo_server.pl with various settings and note the results.

Basic Death

What do we see if we have an action that dies?

Edit lib/Controller/Root.pm so that the index() dies (af2a29e):

sub index :Path :Args(0) {
    my ( $self, $c ) = @_;
    die 'Shot through the heart!';
    $c->response->body( $c->welcome_message );
}

Updates to CPAN module reviews

I've updated all of the CPAN module reviews I've done so far. In all of them the performance and coverages tests have been re-run.

Modules for generating passwords
  • Data::Random has a new maintainer, Buddy Burden, who just released 0.06 (and made his first post here.
  • App::Genpass 2.20 has been released: this adds minlength and maxlength parameters.
Looking up the location of an IP address
  • Added Geo::Coder::HostIP, which I'd missed previously. I've put a bug-fixed version on github, and have started the process to get co-maint, so I can release an update to CPAN.
  • A new version of IP::QQwry has been released.
Spelling out numbers in English
  • I've taken over maintenance of Lingua::EN::Numbers, and resolved all outstanding issues.
Parsing User-Agent strings
  • I've taken over maintenance of HTTP::Headers::UserAgent and released a new version which is more clearly marked as deprecated (and also fixed some bugs and improved test-suite coverage.
  • New versions of HTTP::BrowserDetect and Parse::HTTP::UserAgent.

Marpa::XS release candidate now available

I am very happy to announce that the latest release of Marpa::XS is a release candidate for the first full release, Marpa::XS 1.000000. Most user's experience with the previous beta releases seems to have been trouble-free. The one significant issue that was identified was a failure to properly evaluate null symbols under an unusual combination of circumstances. This problem (a one line error in the C rewrite of the parse engine) is fixed in this release. Unusual as the issue is, when it does occur it results in a parse failure, so that I recommend that all users of Marpa::XS upgrade to the latest release.

Marpa::XS is being kept stable. Bug fixes, even of minor and cosmetic bugs, will be made, as will changes that improve maintainability. But no new features will be added. Interface changes will be especially avoided.

What is Marpa?

Marpa is an advance over recursive descent and yacc. I hope the Marpa algorithm will become the standard parser for problems too big for regular expressions.

One Quarter Until YAPC::NA 2012

Fire up your smart phones and mark down these dates: June 13-15. You’re going to be in beautiful Madison, WI for YAPC::NA 2012

While you’re at it, send your spouse and email and tell him or her that they are coming with you to YAPC. They can enjoy our amazing Spouse’s Program during the day, and hang out and socialize with us at night. 

While you’re at it, why not go buy your badge today, book a flight, and reserve a hotel room?

[From the YAPC::NA Blog.]

If you look on every exit as being an entrance somewhere else ...

I didn’t write anything specifically about Perl this week, but I did broach a topic in my other blog that you may find interesting if you’re a professional programmer.  Check it out, if you like, or not.  If nothing else, it has a reference to a great blog post which is much better than mine. ;->

The Triumphant Return of Zoidberg -- A Modular Perl Shell

After more than a year of hoping to be able to say this, here goes: Zoidberg is back!

What is Zoidberg you ask? Well its a Perl shell, of course. Think of the fun of it all:

mv($_ => lc($_)) for grep /[A-Z]/, <*>

If you use a reserved Perl word first or if you wrap code in a block it is interpreted as Perl, if not then its a shell command. Along with having most of the things you would expect from a shell, it features plenty of extra bells and whistles, like a multiline input system (when Term::ReadLine::Zoid, part of Bundle::Zoidberg, is installed) and automatic splitting of variables to arrays like @PATH which is just $ENV{PATH} split on :.

When used as your login shell, it can be used from inside other programs like vim.

:!cat % | {/^\S/}g | wc -

Further, it is easy to extend with the Zoidberg::Fish plugin system.

use B::Stats to check for less bloat

I'm constantly concerned about small modules or p5p adding more and more bloat, especially "innocent" dependencies. The authors obviously do not care about memory on small devices or vmware hosting with 256MB, and since Moose is so popular obviously also do not care about serious run-time penalties loading all this cruft for almost no gain.

My top concerns are:

1) use warnings

which depends on warnings::register and Carp, which loads a whole bunch of big generally unnecessary warnings category hashes. And XSLoader. And B if compiled. With B::C I introduced -fno-warnings for 5.13.5 to save 68KB executable size on 32-bit. Uncompiled the numbers are of course obscenely higher.

2) use Carp

I’m excited to tell you that Larry Wall, the creator of...



I’m excited to tell you that Larry Wall, the creator of Perl, will be joining us at YAPC::NA 2012. We’re going to be doing a number of things with Larry this year, but I want to tell you about the first two. 

As many of you know we’ve replaced the auction with a raffle. Larry is one of the things we’re raffling off! More specifically, we’re raffling “Lunch with Larry”. Who wouldn’t want to have lunch with this guy? When you buy a ticket for the Lunch with Larry raffle you’ll have 9 opportunities to win! We’ll choose 3 people, each of the 3 days, to go have a bite with Larry and talk about whatever you like.

We’re also going to have a little fire-side chat with Larry at the end of the conference. We’re calling this “One On One With The Great One”. It will basically be an open forum for Larry to address the entire crowd, and for you to ask him some of your most pressing questions. 

[From the YAPC::NA Blog.]

The Ten Minute Thinking Rule

What’s the problem?

This idea was shared with me during a retrospective session at $employer when I was expressing some frustration at people starting to:

Ask first, think never

I’m at least as busy as the next person and I have my own mountain of work to complete. Despite being regularly cantankerous, grumpy, cranky and disagreeable people still come to me with a variety of questions … I think I have a good combination of detective skills, google-fu and luck that makes me appear more magical than I really am.

The Ten Minute Thinking Rule

Simply put:

You may only interrupt another co-worker to ask a question if you have sat on your own for ten minutes and tried to figure out the solution yourself

Corollary

When asked, you must be able to demonstrate that you’ve made some effort

The Ten Minute Thinking Rule isn’t an exercise in pretending you’re thinking.

Some ‘thinking’

Thinking also includes basic investigations. Consider some of the following:

Perl Calltrace

How to get the abs path of the script that do use modulename ?

  • In the module:
 1 package foo;
 2 use common::sense;
 3 use Cwd 'abs_path';
 4 
 5 sub program {
 6     say abs_path($0);
 7 }
 8 
 9 1;
 

Activate ipv6 on Windows

$ cpan IO::Socket::INET6

t/blocking.t .......... IO::Socket::INET6: socket: Address family not
supported by protocol at t/blocking.t line 34.

t/blocking.t (Wstat: 27136 Tests: 0 Failed: 0)
Non-zero exit status: 106
Parse errors: Bad plan. You planned 2 tests but ran 0.
t/host6.t (Wstat: 27136 Tests: 0 Failed: 0)
Non-zero exit status: 106
Parse errors: No plan found in TAP output
t/io_sock6.t (Wstat: 27136 Tests: 0 Failed: 0)
Non-zero exit status: 106
Parse errors: Bad plan. You planned 20 tests but ran 0.
Files=9, Tests=10, 14 wallclock secs ( 0.09 usr 0.05 sys + 1.72 cusr 2.23
csys = 4.09 CPU)
Result: FAIL

$ netsh interface ipv6 install
The following helper DLL cannot be loaded: DGNET.DLL.
Ok.

$ cpan IO::Socket::INET6

All tests successful.
Result: PASS
SHLOMIF/IO-Socket-INET6-2.69.tar.gz
/usr/bin/make install -- OK

Perl in a Trading Environment: A Multi-Pronged Success Story

Sean Blanton will give a talk at YAPC::NA 2012 described as:

Perl has proven itself in our start-up trading strategy in many different areas: system and application administration, networking, data collection, reporting, website and recently analytics with PDL.

For every task, we have evaluated the best tool for the job and decided on Perl because of the wide variety of available **tested** modules, and the ability to share code for very different tasks. Perl’s close relationship with C is a big plus. A set of generic services built up using Moose and Bread::Board has been particularly effective for code reuse. All of this helped reduce implementation time and free resources for other tasks, such as strategic analysis and planning, which in turn helped accelerate revenue growth.

[From the YAPC::NA Blog.]

Announcing MooseX::Types::NumUnit

I use Moose to write scientific simulations, including one very large simulation with a user api. To this point all of the numerical quantities, kept in attributes, needed to be of Num type. This always meant an implied covenant between the me and the users, which was to use SI units.

However I have a few quantities that I want to use eV units, which makes a lot more sense. Therefore I setup a simple type with coercion to accept a string num eV and coerce it to a number given by qe * num. This got me to thinking, why can’t I do this for all my units?

To answer this need, I present MooseX::Types::NumUnit which provides a couple static types, but also provides the function num_of_unit, which creates anonymous types which will automatically coerce a string to a number of the desired unit. For example:

CPAN Testers Summary - November 2011 - Sounds of the Universe

November turned into a rather more traumatic month than I would have liked. It didn't start well with the old hosting company issuing us a invoice for 1 year's hosting, which we had previously cancelled due to their appalling service regards our loss of data. They now claim we still owe them a month, regardless of the month outage we suffered due to their incompetence and failure to replace our mirrored HDD before the second one failed. I'm now seeking compensation, but I'm not hopefully it'll get very far.

The SQLite issues are still surfacing. Following a complete rebuild of the SQLite database, Andreas is still seeing errors for some searches. Though not all, so those of you who use the SQLite download, may see intermittent faults. I have no idea why this happens and if there are any SQLite experts out there, feel free to get in touch.

How to parse HTML, part 2

This is the second of a series of posts that details a Marpa-based, "Ruby Slippers" approach to parsing liberal and defective HTML. This post assumes you have read the first post.

First, reduce the HTML to a token stream

Most computer languages can be viewed as a token stream. HTML is not an exception. HTML tokens can be blocks of text; comments and various other SGML entities; HTML element start tags; and HTML element end tags. The HTML token stream is unusual in that some of its tokens can be quite complex internally.

In parsing computer languages, it is a frequent practice to divide the work between a tokenizer ("lexer") and a high-level parser . The lexer takes the raw input and turns it into a token stream. Tokenizing HTML is a difficult job, and one for which there is an excellent CPAN module: HTML::Parser . Marpa::HTML relies on HTML::Parser to do its tokenization.

Marpa::HTML

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.