Last call for review of Test-Builder using Test2 (Formerly Test-Stream).

On October 29th, 2015, I released Test-Stream as stable. I did this because I felt it was ready, and because I was no longer receiving any feedback from perl-qa asking me to change things. Since that release, the feedback picked up substantially. It seems that declaring something done is the best way to find out ways in which it is not actually done.

Here are the big things people wanted:

  • Split the dist into multiple dists, making the internals and tools separate.
  • Abandon the loader system (use Test::Stream -/:/etc)
  • Loosen the tight coupling of Test::Steam to TAP
  • Make context() less magic (don’t use INTERNALS::SvREFCNT)
  • Use less import() magic
  • Better namespace structuring
  • Changes to how SKIP and TODO are implemented

We decided that the best way forward was to forget about compatibility with Test-Stream, which is still new enough that it is not seeing much use, and make a new name with everyone’s changes. That’s Test2.

After the split there are 3 distributions:

CPAN Weekly: one module per week, in your inbox

CPAN Weekly is a mailing list for Perl 5 programmers. Each week there will be one short message sent to the list, with a brief description of a CPAN module, and example usage.

The idea is not to provide a tutorial, but just to make you aware of the module, and show one basic use case. By planting seeds in your mental Perl toolbox, hopefully next time you have certain needs you will think "oh, I read about a module for that!", rather than "I'll just write a module for that".

You can sign up at cpan-weekly.org.

Stupid state trick

Occasionally I find myself writing a Perl subroutine that uses a module that no other part of the code needs. This subroutine may be called multiple times, or not at all. At some point I wondered if putting some logic around the require statement would be faster than just calling it every time. require() is idempotent, after all. You could do something like $counter++ or require Foo;, but the variable has to live somewhere outside the subroutine. Not neat.

It occurred to me that, given Perl 5.10 or greater, something like state $dummy = require Foo; might do the trick. I would be willing to bet this is a use of state that was not anticipated when it was designed. But does it actually do what I want, and is what I want worth doing?

The answer to the first question is "yes." A quick script with require overridden proved that the module was in fact loaded, and that require was called only once no matter how many times it was executed.

How to Make a Perl 6 Module (Bit Rot Thursday)

Happy Bit Rot Thursday! This week I'm taking care of fixing minor issues with packaging of my Perl 6 modules, and so, I'll talk about the general process of releasing a Perl 6 module. Let's dive in!

Prelude

Perl 6 is a brand new language, so there's yet no well-established module system like what Perl 5 has, but there is a work in progress. Thus, I'll first describe the process for our temporary GitHub-based system and then I'll talk about the PAUSE-based system that's being worked on.

There are some tools and helpers available to help with the process of module development, but they are beyond the scope of this post.

Terms (and no conditions)

Memory savings with cperl and AvSTATIC

B::C and cperl has now proper support for copy-on-grow (COG) and copy-on-write (COW) arrays.

COG means that the array of SV* pointers is allocated by the compiler statically, not dynamically, and that the cperl runtime creates a new array whenever the array is extended (copy-on-grow).

COW means that the array of SV* pointers is allocated by the compiler constant and static in the .rodata segment, and that the cperl runtime creates a new array whenever an element of the arrays is changed (copy-on-write).

With a typical example of a medium sized module, Net::DNS::Resolver, the memory usage is as follows:

FOSDEM 2016

What’s in a name? that which we call a rose By any other name would smell as sweet; (William Shakespeare, Romeo & Juliet, Act II Scene ii)

I went to FOSDEM in Brussels this year as a representative of the Perl Foundation. As such I spent the weekend doing my best to be a good advocate of the Perl programming languages.

FOSDEM for those of you in gentle unawareness is probably the world's largest, free, Open Source event. It is held each year in Brussels, Belgium, and attracts speakers for hundreds of talks on dozens of projects, languages and distros. The event is attended by over seven thousand people from almost everywhere in the world.

Focussing Haskell on Perl 6

On the bus ride out to Charleroi I caught a stray brainwave about how to properly notate at least some of Haskell's Lens library, so I wrote up some notes on it. This is going to be slightly spooky, but not much more than the previously-existing ability to bind one data structure to another.

I do want to finish up the Scheme work, if only to prove the crowd on Perlmonks wrong, first though.

The 'lens' library is essentially a metaphor for focussing in on your data, in roughly the following sense:

Twisty little passages

I came across an excellent book on mazes, written for programmers (Mazes for Programmers). My only complaint is that all the examples are written in ruby. All is good though, as I work through the book, I will be converting the examples into working perl examples, detailing that experience here.

I also came across a perl module that makes some good mazes Games::Maze which also has some TODOs. Bonus! I'll take what I learn and apply it to that distribution, hopefully making Games::Maze into the goto resource for making maze-like games in perl.

I am not the author of Games::Maze. I hope that he/she is ready for some pull requests. 8)

FOSDEM 2016

To me It seemed a particularly good FOSDEM for both for Perl5/6 and
other talks although very crowded as usual and I didn't see the usual
*BSD or Tor stalls. I was stuck by the statistic that there were
about 500 speakers from many thousands of people so of the order of
one speaker per tens of attendees which is very high.

Videos are already starting to appear at

http://video.fosdem.org/2016/

On Saturday I started with Poettering and systemd which was a keynote
and perhaps a little disappointing since he usually is a better
speaker and the audio was a little indistinct. systemd had won being
used by all distros except gentoo and slackware. They were now working
on a dns resolver component which supported DNSSEC although in
practice validating signed zone files would slow down browsing and
currently only 2% of websites had it activated. He didn't mention
strong criticisms of its security by crypto experts such as DJB.

Rakudo Perl 6 Compiler - 2016.01.1 released

This release includes primarily bugfixes, should be no breaking changes from the Christmas release.

Thanks to everyone for your patience as we figure out our release setup and how to add new features without breaking compatibility with the 6.c spec.

A Rakudo Star release should follow in the next few days, hopefully in time for the NY.pm Perl 6 hands on workshop this weekend.

If you want a tarball, you can download the compiler from http://rakudo.org/downloads/rakudo/ -- Additionally, it's available via macports already.

Perl 5 Porters Mailing List Summary: January 25th - February 1st

Hey everyone,

Following is the p5p (Perl 5 Porters) mailing list summary for the past week. Enjoy!

Get an in-browser remote desktop with Mojolicious and noVNC

The article itself is published at PerlTricks. This is the second article I’ve published there (the first was about How to send verification emails using Mojolicious). Hopefully more to come!

Perl 6: Shortcuts (Part 1)

Programming is a task where laziness is a virtue. We write modules to avoid repeatedly writing subroutines. We write subroutines to avoid repeatedly writing loops. We write loops to avoid repeatedly writing code... And there's another level of laziness: we use language shortcuts to avoid writing too much code.

Shortcuts are a controversial subject. Some say they make code faster to write and easier to read. Some say they make it harder to understand for people unfamiliar with those shortcuts. So this article is merely telling you about shortcuts and it's up to you to decide whether to use them or to avoid them. Let's begin, shall we!

Public Getter/Setter for Class Attributes

The concept of a "getter" and "setter" is common in many languages: you have a "thing" in your class and you write a method to set or get the value of that thing. In verbose Perl 6, such a set up might look something like this:

IO::Iron - Towards Update to Version 3

HTML Content Extraction / Instapaper

I recently found the old Instapaper extraction rules to rewrite HTML content in a way that is easier on the eyes for consumption. This find has resulted in me writing HTML::ExtractContent::FTR and HTML::ExtractContent::Pluggable to get a nice/concise way to scrape HTML from sites for consumption via RSS or mail.

MVC with Dancer2 and DBIC: Form Validation

A few days ago I pushed to GitHub a sample web application written in the MVC style with Dancer2 and DBIx::Class. In this very first post about it, I'd like to highlight
how a route block that processes and validates form data can be made short and neat with the help of HTML::FormHandler.

Consider this HTML form from the application which creates a new user:

signup-form.png

Perl 6 .rotor: The King of List Manipulation

Rotor. The word makes a mechanic think about brakes, an electrical engineer about motors, and a fan of Red Letter Media YouTube channel about poorly executed films. But to a Perl 6 programmer, .rotor is a powerful tool for list operations.

Break up into chunks

At its simplest, .rotor takes an integer and breaks up a list into sublists with that many elements:

say <a b c  d e f  g h>.rotor: 3
>>>OUTPUT: ((a b c) (d e f))

We have a list of 8 elements, we called .rotor on it with argument 3 and we received two Lists, with 3 elements each. The last two elements of the original list we not included, because they don't make up a complete, 3-element list. That can be rectified, however, using the :partial named argument set to True:

Social Media Meta Tags

Social Media Meta Tags

Social media meta tags are HTML tags that allow you to make the most out of the content you share from a URL. You can determine what information is displayed from a post in Twitter, Facebook, LinkedIn, Pinterest and beyond. It gives developers control over the experience their content produces, as it shows up on these social networks.

UTF-16 and Windows CRLF, oh my

I recently had to do some quick search/replace on a bundle of Windows XML files. They are all encoded as UTF-16LE, with the Windows \n\r line endings encoded as 0D 00 0A 00.

Perl can handle UTF-16LE just fine, and it handles CRLF endings on windows out-of-the-box, but the problem is that the default CRLF translation happens too close to the filehandle- on the wrong side of the Unicode translation. The fix is to use the PerlIO layers :raw:encoding(UTF-16LE):crlf - the ":raw" prevents the default CRLF translation from happening at the byte level, the UTF section translates between characters and the encoded bytes, and the final ":crlf" handles the line endings at the encoded-as-UTF16 level.

Knowing that is half the battle. The other half is applying those layers. This was a one-time, quick-and-dirty command-line edit, along these lines:

perl -pi.bak -e "s/old-dir/new-dir/gi" file1.xml file2.xml file3.xml

curl + swat VS selenium

No, this is not about holy war ! I do respect other tools (-: , really

But rambling on stackoverflow I found quite interesting question about web tests automation. The author started using curl for quite simple test automation task and then changed to selenium web driver, the reason was quite obvious - curl has request oriented design which make it hard to use it when making complicated, sequential requests in a whole test story.

But curl is still cool stuff to get rid of , but you don't have to ... if you use swat PLUS curl.

So here is my answer ...

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.