New Moose for Old.

Some of you might remember an earlier post where I was playing about with ARIS Express and created an org chart to map out some of the roles that might be used in my AD&D Character class.

At the end of the post I mused about reading the ARIS file and gleaning out the data I just typed in and generating roles with them. Well I did spend a little time puttering about and even looked at 'FreeMind' and even at a new one called jsULM2. Well all of those where nice but each requires me to do a good deal of fudging to get anything out. Mostly silly little things like calling a UML 'stereotype' or 'multiplicity' a moose role and really It would be confusing to use.

Also had a quick peek on CPAN and found Padre::Plugin::Moose so I had to look at that. After I installed it I found 'Moose Assist' under the Tool menu and it looks like this;
Mooseass.jpg

A Marpa use case: JavaScript Regexp Implementation

Introduction

Back working on the next version of MarpaX::Languages::ECMAScript::AST, one important missing thing was implementing in Perl the equivalent of JavaScript Regular Expressions Engine. Despite JavaScript borrowed the perl's syntax, its semantics behave differently, and one should never copy a regular expression from Perl into JavaScript blindly.

For instance, a vicious difference is that a capture value in JavaScript is the last match. While in Perl this is the last successful match. Consequence can be hard to track down, for example, this regexp:

 /(z)((a+)?(b+)?(c))*/

applied on this input:

 "zaacbbbcac"

will capture, in JavaScript:

 <z> <ac> <a> <undefined> <c>

while perl will say:

 <z> <ac> <a> <bbb> <c>

Finally, a nice exercice and the occasion to show what can be achieved with Marpa::R2 Scanless Interface.

Implementation

ECMAScript specification has a nice writeup of its regular expression grammar and semantics, and it appears that the grammar itself is simple (c.f. the _DATA__ section):

Polyglot pattern matching in London

Years ago I created a training class that has proved one of my most enduring, popular...and frustrating: Understanding Perl Regexes.

The class has endured because regexes are still one of the sharpest blades on the Swiss Army Chainsaw, and have consistently become even sharper with almost every major release of Perl, as new features have been added and the underlying implementation has been improved.

The class has been popular because all those powerful added features have also made Perl's regex dialect more complex, more line-noisy, and sometimes just plain scarier than anyone else's. Having someone to guide you though the labyrinth can be invaluable so I've kept looking for ways to help students see beyond the complexity and come to grips with what regexes really are, how they actually work, and how they can be deliberately designed (you know, instead of just metastasizing).

Perl and Me, Part 9: That's Why I Failed Recess

This is part 9 of an ongoing series where I explore my relationship with Perl.  You may wish to begin at the beginning.

This week we look at Getting Shit Done.

Last week I pointed out that one reason I stick with Perl is because it keeps evolving, so I never seem to get ahead of it.  But that’s not the reason I switched in the first place.  And that reason is still just as true today as it was 17 years ago: Perl is the language that Gets Shit Done.

Programming in C++ was fun, and I talked a bit about some things I missed in it.  But I also mentioned the big problem with coding in C++: you’re always writing libraries.  C++ is a very high-level low-level language.  That is, it makes it easy to code just about any data structure or algorithm you can think of.  Which is pretty awesome.  If you want spend your life coding data structures and algorithms.

Whereas, in Perl, it’s also easy to write all those things ... except that you never have to.  ‘Cause, in Perl, they’re already written.

I Hate Cheats

I never liked cheats and while playing with Acme::Moose I figured out I can easily cheat by setting any of my values or peeking at them while I was playing. As we are able to do this sort of thing


my $moose = Acme::Moose->new; 
$moose->feed; 
if ( $moose->happiness ){
...

Of course as my variables are 'rw' this little problem is all my fault.

In the original Acme::Llama the internal global variable hash value


package Acme::Llama;

our %llama;

Toolkit review: Devel::Local, Devel::SimpleTrace, Reply

Nothing makes a lazy programmer happier than discovering free software that makes her or his job easier. Here are three of my favorites that I use on the daily:

Devel::SimpleTrace

Devel::SimpleTrace will add stack traces to 'die' and 'warn'. If you've ever seen library code that you don't recognize throw an error you don't understand this module should be in your toolkit.

SYNOPSIS

 #adapted/copied from the pod
 $ perl -MDevel::SimpleTrace program_with_strange_errors.pl

or just put a 'use Devel::SimpleTrace' anywhere.

Basics of reading stacktraces:

  • Skim from top to bottom.
  • Stop when you see files that you wrote/recognize, and find the edge between files that are in your control and files that are out of your control.
  • Work from there outwards until you identify the problem.

Devel::Local

Planet Moose - January 2014

Welcome to Planet Moose, a brief write up on what's been happening in the world of Moose in the past month, for the benefit of those of you who don't have their eyes permanently glued to the #moose IRC channel, or the MetaCPAN recent uploads page.

If you'd like to contribute some news for next month's issue, you can do so on the wiki.

Moose

There have been a couple of minor releases of Moose this month (2.1201 and 2.1202) but nothing especially exciting.

AmsterdamX.pm hosting a Perl hackathon!

At AmsterdamX.pm we decided to cook up a special surprise this cold February: we're hosting our first hackathon!

But since we like surprises, there is one more surprise. We will have a special guest: Stevan Little. Yes, that Stevan Little.

Tip-toe in the Moose Patch

Well my last post I explored a little bit of the shinny new Test::Moose::More by adding a few tests to my Acme::Moose class.

I left off with the idea that I could use a test that tells me that I have extra attributes in my 'class'. Not being much afraid to muck about in source code I had a look in 'Test::Moose::More' to see what would be involved in creating such a test.

Well after a few min of poking about I settled on just extending the 'validate_thing' sub by adding in a new Key, 'no_extra_attributes', on the attributes hash. If this key is present then my little test will kick in and report any attributes that are not on the list passed in via the 'attributes' key.

Here is the patch

Dancer 1.3118 and Template Toolkit

I just got caught by a change in Dancer 1.3118 and so I thought I’d share with you. As of 1.3118 Dancer no longer sets default variables for template toolkit if you subclass it. You’ll want to add these variables to your config.yml file in the engines template_toolkit section:

ABSOLUTE : 1

ANYCASE : 1

INCLUDE_PATH : /path/to/views

These variables all used to be set automatically, but when you upgrade you’ll get this error: 

absolute paths are not allowed (set ABSOLUTE option)

[From my blog.]

Back to Zurich

I'm just putting the final touches on another speaking tour through Europe (so expect more posts as I nail down destinations and events). I seem to be working backwards though, because the very last event of the visit—in Switzerland in early April—is already solid.

Once again I'll be offering a week of public classes at ETHZ, including:


You can view the complete list of courses and even sign up for them now.

We're also hoping to offer a free public talk in Zurich one evening during that week. I'll blog the details of that event as soon as we know them.

A newer Shell::Perl

While trying to install Pod::Server under Perl 5.18.2, I found 2 problems:

  • Text::VimColor dies with encoding issues. These are being investigated by Randy Stauner.

  • Shell::Perl died. I forked the github project and fixed it. So, if you need it, try:
    https://github.com/ronsavage/pirl

Cheers
Ron

Does it Pass the Moose Test?

The title of this entry will only mean something to a very select few in the world and if you think it has anything to do with perl look below

Jeep-Grand-Cherokee-Moose-Test.jpg

Anyway I just finished my version .02 of Acme::Moose as I totally botched version .01 as it is a llama not a moose.

However, that is another story. At least I decided to add in a little testing to this version and what the heck I might as well use the fancy new Test::Moose::More and see what it has to offer.

So after about 10 mins of installation from CPAN I was ready to give it a try.

Well at first glance it took a few mins and a couple of runs of my .t to figure out that 'Test::Moose::More' is really just for testing Moose classes so you have to fall back to something like 'Test::More' if you want to run regular type test, but no matter.

So my first test looked like this

Another time-tracking post

Following Steven Haryanto's post on how he tracks his time, I thought some people might be interested in the time tracking solution I'm currently using.

My colleagues and I are required to track our daily activities for billing purposes. Ultimately the information needs to end up in the company work-request management system ('WRMS') but that system's user interface for timesheeting is somewhat frustrating. In response to this, two colleagues (Martyn Smith and Nigel McNie) wrote a Perl script called TKS. This allowed people to enter their activities in a plain text file in a format similar to Steven's. Then they could run the TKS script periodically to sync the contents of the file into WRMS (a modular architecture allows different backend systems to be supported).

An example of a day's entries might look like this:

fatal warnings are a ticking time bomb (via chromatic)

chromatic just blogged about the perils of fatal warnings pushed down CPAN by the otherwise exceedingly useful Moo perl library. Since his comment system is perpetually broken, with his permission I am moving the discussion here, where the comment system is... right, anyhow.

What follows is the verbatim text of chromatic's post. My own thoughts are going to be in the form of a comment.

The behavior in scalar context is undefined.

I was just reading the docs of Email::Address when I encountered this warning. I know this is not the only place where the behavior in scalar context is undefined, but I wonder. Wouldn't it be better to throw an exception or at least print a warning when a function such as the parse method of Email::Address is called in scalar (or void) context?

That would eliminate the incorrect usage faster probably also reducing the questions asked by users. It will also make it easier to add a different functionality later on, without surprising the people who used the method incorrectly.

Not a Llama

Really did not have much to do before heading out to a show and was randomly looking at a few things and bumbled across this pic

moose_plus_llama_makes_____by_iceclanwolfwarrior-d39um8i.png


Then being inspired to look on CPAN I found this ACME::Llama so I just had to do this

Downloading age-restricted videos from YouTube

booTube.png

First off, I'd like to compliment Yuji Shimada on his fantastic module WWW::YouTube::Download. I'm sure the module requires a lot of maintenance (as sites like YouTube can change their design quite a bit) and for that I'm grateful.

Now, the module worked perfectly for my downloading needs *except* that I could not fetch age-restricted videos. Instead I received a message that the module could not find any video URLs. The bright side to this problem was that Shimada's module made it *very* easy to come to a solution, thanks to the module's ua method which accepts a LWP::UserAgent object.

TL;DR - cookies

In my case, I was using Mechanize, so I passed the Mech object to the ua method, like so:

Announcing Pinto 0.099

CPAN-Gump.png

Pinto is a powerful tool for creating and managing a private CPAN. Pinto make it easy to control your dependencies and ensure your app is built with the right module versions every time. The latest release (0.099) includes a boatload of exciting enhancements. Here are the highlights[1]:

MongoDB wants Perl programmers

If you love Perl and are interested in MongoDB, we want to hire you. Feel free to drop me a line at friedo@mongodb.com if you're interested, or take a look at the official posting here. The full job description is below.

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.