Smarty Pants Moose

Its back-fix code day here in the Moose-pen

In yesterday's post-ette I ranted on about how much of a smarty pants I was to use a 'param' in as the type for my 'message' part of a case statement. That was working fine until I blundered across this perfectly valid SQL


SELECT StockID, OnOrderQuantity,
   CASE
     WHEN Stock - OnOrderQuantity > 30 THEN  'Over Stocked'
     WHEN Stock - OnOrderQuantity > 0 AND Stock-OnOrderQuantity <=30 THEN 'Stocked'
     ELSE Stock - OnOrderQuantity
   END
FROM Stock;
The 'else' in this case is an 'expression' and if I prototyped this out like this

Rakudo.js update - NFG / unicode collation and role bug fixes

Rakudo.js update - NFG, unicode collation and more bugfixes

Rakudo.js has been in bugfixing mode recently.

Rakudo.js now uses NFG (Normal Grapheme Form) semantics in some places.
This means some string operations treat strings as sequences of graphemes instead of unicode code points. Graphemes are "user-perceived characters" (See http://unicode.org/reports/tr29/). This isn't done everywhere yet but it allows us to pass a bunch of roast tests.
Because JavaScript doesn't use graphemes underneath in it's string implementation like MoarVM does using NFG semantics can be much more expensive.
As such in low level setting code we often want to use the native javascript semantics when they are good enough.
To make that a choice I added a bunch of NFG aware op variants like (nqp::charsnfg) so we can pay the price only when it's necessary.

Running Perl for your car's dashboard display

About time!

Perl 6 Core Hacking: QASTalicious

Read this article on Rakudo.Party

Over the past month, I spent some time in Rakudo's QAST land writing a few optimizations, fixing bugs involving warnings, as well as squashing a monster hive of 10 thunk scoping bugs with a single commit. In today's article, we'll go over that last feat in detail, as well as learn what QAST is and how to work with it.

PART I: The QAST

"QAST" stands for "Q" Abstract Syntax Tree. The "Q" is there because it's comes after letter "P", and "P" used to be in "PAST" to stand for "Parrot", the name of an earlier, experimental Perl 6 implementation (or rather, its virtual machine). Let's see what QAST is all about!

Dumping QAST

Every Rakudo Perl 6 program compiles down to a tree of QAST nodes and you can dump that tree if you specify --target=ast or --target=optimize command line option to perl6 when compiling a program or a module:

Moose Case Explained

It's explain post-ette day there in the Moose-Pen

As I reviewing some of my code for 'Case' statements I had chanch to stop and think about why I was using a Param class for the message on a case. Right now I have something like this;

           {
                left       => { name  => 'Price', },
                right      => { value => '10' },
                operator   => '<',
                message => { value => 'under 10$' }
            },
Before I had that just as a simple string like this

                message => 'under 10$'

Call for Presenters TPCiSLC 2018

Talk submissions for #TPCiSLC are currently being accepted! Round 1 closing/Round 2 opening Jan 28/29.

We will be accepting proposals for the following session types:

Short Talks (20 minutes)
Standard Talks (50 minutes)
Tutorial Sessions (80 or 110 minutes)

To submit proposals for a talk/presentation, please fill out this form: https://goo.gl/forms/2qxdfgtRsdc6lXBZ2.

We encourage you to submit your talk as early as possible. We will be choosing speakers in an ongoing process, with the final submissions to be accepted no later than March 18th, 2018.

Round 1: January 1st - January 28th, speakers notified by 2/7/18
Round 2: January 29th - February 25th, speakers notified by 3/7/18
Round 3: February 26th - March 18th, speakers notified by 3/28/18
Final Speaker Lineup Announced: April 1st, 2018

Apply at https://goo.gl/forms/2qxdfgtRsdc6lXBZ2

More information at https://perlconference.us/tpc-2018-slc/cfp/

Simple (Date) Range Overlap Detection

I started down this particular rabbit hole when (a) I had to check for date range overlaps when worrying about scheduling appraisals; and (b) my attempts to use SQL BETWEEN resulted in complicated, hard-to-read SQL.

Now you would think that BETWEEN should give you easy-to-understand SQL for date ranges. Maybe in the hands of others BETWEEN does, but for me by the time I accounted for all of the cases the BETWEEN-based SQL date range overlap detection got more complicated than I thought it needed to be. So I drew up some diagrams, which eventually led me to the realization that this:

dateA.start <= dateB.end
        AND
dateB.start <= dateA.end

is all that you need. No BETWEEN needed, simple to read, and should work in any useful dialect of SQL.

A Simple Telegram Bot

I just wrote a small post A Simple Telegram Bot in my blog... with a tiny introduction to Bot::ChatBots::Telegram. Comments more than welcome!

Moose Test All Again??

Its test post-ette day again here in the Moose-Pen

I guess I am following a very predictable pattern The weekend is here and I just do a post on test results. Well why spoil a good thing?

Since my last test round I have changed a good number of things about but I am fairly sure that Database::Accessor is in good shape though I am not looking forward to see what sort of state Driver ::DBI is in.

As I suspected there was only very minor problems with Database::Accessor;

Looks like you planned 2 tests but ran 6.
t/15_case.t ................. Dubious, test returned
I just have to update that test count and now I get

Abusing Multiple Dispatch in Perl 6 for fun and profit

Abusing Multiple Dispatch Creatively is avallable on my blog for perusal. Comments and questions welcome as always.

Perl 5 Porters Mailing List Summary: January 2nd-9th

Hey everyone,

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

Enjoy!

Testing FIDO/U2F Two Factor Authentication

This month, I was tasked with implementing FIDO/U2F support for two factor authentication for a client. U2F two factor authentication requires a FIDO/U2F hardware key that you insert into your devices USB port and press a button to complete two factor authentication. There are many different vendors that make these devices, such as Yubikey etc. Thanks to the excellent Authen::U2F module by CPAN author ROBN, and Google's u2f-api.js library, implementing support for this proved to be fairly straightforward, but the process for doing this is not the point of this blog post.

The point of this blog post is that, at the time, there was no easy way to write any kind of automated tests for this. As a result, I ended up writing Authen::U2F::Tester. Authen::U2F::Tester acts like a virtual hardware device to complete FIDO/U2F registration and authentication (known as signing in U2F terms) requests.

Moose Coerce Case

Still case day here in the Moose-Pen

Following on from yesterday's post I first want to make a little changes to my 'Case' class; I think it will be better to have this

--has 'case' => (
++has 'whens' => (
            isa         => 'ArrayRefofWhens',
            is           => 'ro',
            required => 1,
        );

Test::Snapshot - automate externalising "expected" data

During the ongoing development of graphql-perl, I have found it valuable to generate data structures, and to compare those with expected values. Often, these have been highly detailed rather than a subset, because I wanted to know when anything changed.

When, however, something does validly have to change, it might change quite a few "expected" outputs. If those all need updating manually, that is a lot of repetitive activity. What if the computer could do that instead? What if Perl had "snapshot testing" as used in JavaScript frontend development, most popularly in Jest?

use Test::Snapshot;
my $got = function_generating_data();
is_deeply_snapshot $got, 'test description'; # could also be in a subtest

Simple tree walking in Perl 6

Check out Tree Surgery for a quick guide on how to easily walk generic trees of Perl 6 data.

Some Maths for Dobble

I wrote an article about the maths behind the game Dobble (known as Spot-It in some countries). It has no pretense of strict formality but it works for reminding me the though process that leads to designing Dobble-like games. The whole process prodded me to write Math::GF, a module on Galois Fields that can be used together with Math::Polynomial, so... there's also Perl in it!

The Moose When

It is another head case day here in the Moose Pen.

So yesterday I left you hanging on how I was going to incorporate the 'case' statement into Database::Accessor hopefully today I will find some solution for it.

To start off my attempts to use the present class structure ended in failure and from my analysys of the problem I have one of two choices.
  1. Add in new attributes
  2. Add in a new class
The main disadvantage of the first solution is I will have a number of attributes that will be useless 99.99% of the time. The advantage is this will most likely be the least disruptive to my code base and use the least amount of code.

The second solution has no disadvantages that I can see but it will increase my code base a little.

Long Live Perl 5!

You probably have read a recent Open Letter to the Perl Community. The letter has generated a lot of response (173 reddit comments as I write this). Unfortunately, a lot of the responses are quite negative and do not match my understanding of the letter.

I figured I share my interpretation of the words and if that interpretation does not match the author's intent, I hope my interpretation captures the mood of the community on the matter.

A Radical Idea

The first thing the letter talks about is what it calls a "radical idea". The suggestion is for Perl 5 compiler to upgrade its backend. Instead of the current Perl VM the perl compiler uses, it would be ported to NQP compiler toolkit and will support all of the backends NQP supports, which currently is MoarVM, as the leading option, with JVM and JavaScript backends at various stages of completion as alternatives.

The Perl Conference in Salt Lake City, 2018

We are pleased to FINALLY bring you the news everyone has been waiting for!

It is with great enthusiasm that we happily announce The Perl Conference in North America, 2018 will be held Sunday, June 17th through Friday, June 22nd at the Little America Hotel in Salt Lake City, Utah!

The main event will run from Monday, June 18th through Wednesday, June 20th. Master Classes, training, and other activities will be held on the 17th, 21st, and 22nd. We highly encourage you to attend all days, but especially look forward to seeing you at the Main Event.

This year’s website is already live and can be found at https://perlconference.us/tpc-2018-slc/.

Call for Participation is live at https://goo.gl/forms/PkYHWD3B4vUKZLrW2. Please consider submitting a talk!

Registration will also be live February 1st, so watch out for that!

Keep watching for additional announcements.

#TPCiSLC

Trying to make confluence usable.

=head1 RESTfluence

I've tried to make this blog post copy/pastable as valid perl and valid markdown. So with luck it can be copy/pasted into an editor if you want to use this.

Confluence. I don't really like it, but the major thing it's got going for it is that it's not Sharepoint. As I am spending the summer holidays doing some documentation at work, one of the things I wanted to do was to make confluence less hateful. So I cracked open the REST API to see how far I could get.

There used to be good tools, but atlassian got rid of the XMLRPC API not that long ago.

Progress I made was:

  • Got a list of all spaces, and all pages in each space.
  • Worked out how to obtain the content of a page.
  • Worked out how to change the content of a page (for when the time comes).

Where I got stuck:

  • Working out how to round-trip the confluence markup to/from markdown.

The rest of this post describes the script I put together. It's not useful enough for me to put on the CPAN but it's worth putting up somewhere.

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.