Selenium and Perl

Selenium and Perl

Some of you might remember the lightning talk I gave at the London Perl Workshop last year (it’s available on YouTube, I’ll wait if you want to watch it). In it, I said I planned to resurrect the Perl School brand, using it to publish Perl ebooks. One book, Perl Taster, was already available and I had plans to write and publish several more. Those plans are still ongoing…

Also in the talk, I asked if anyone else wanted to write a book for the series. I offered to help out with the hard parts of getting your text into the Amazon system (it’s actually nowhere near as hard as you might think). Three people approached me later to discuss the possibility of writing something, but only one followed through with something more concrete. That was John Davies, who has been a regular attendee at London Perl Mongers for a pretty long time. At the LPW, John had helped Martin Berends to run a training course on using Selenium with Perl. As part of that help, John had written some notes on the course which had been distributed to the attendees. John wondered if those notes would be worth publishing as a Perl School ebook. I said that it was certainly worth pursuing the idea.

Over the last few months, John has expanded his original notes considerably and I’ve been doing the work needed to convert his input into an ebook. And I’m happy to say that the book was published on Amazon yesterday. It’s called Selenium and Perl and you should be able to find it on your local Kindle store. If you want to test your Perl web applications using Selenium, then I hope that you find it useful.

It’s been the first time I’ve edited someone else’s work and converted it into an ebook. I think the process has gone well (perhaps someone should ask John for his opinion!)

But I’m confident enough of the process to renew the offer I made at the LPW. If you’re interested in writing an ebook as part of the Perl School range, please get in touch and we can discuss it.

Two New Modules

Vive la Revolution

There was a London Perl Mongers meeting at ZPG about ten days ago. I gave a short talk explaining why (and how) a republican like me came to be running a site about the Line of Succession to the British Throne. The meeting was great (as they always are) and I think my talk went well (I’m told the videos are imminent). The photo shows the final slide from my talk. I left it up so it was a backdrop for a number of announcements that various people gave just before the break.

In order to write my talk, I revisited the source code for my site and, in doing so, I realised that there were a couple of chunks of logic that I could (and should) carve out into separate distributions that I could put on CPAN. I’ve done that over the last couple of days and the modules are now available.

MooX::Role::JSON_LD

The first is called MooX::Role::JSON_LD. It’s a Moo role that you can add to your classes in order to make it easy to generate JSON-LD from your objects. What’s JSON-LD? I hear you ask. Well, it’s JavaScript Object Notation for Linked Data. The most popular use for it is to add structured data to web sites. Adding structured data to your web site makes it easy for Google (other search engines are available) to understand what your web site is about and that, in turn, will hopefully persuade Google to list your site higher than it otherwise would. You can see JSON-LD in action on a couple of my recent projects – https://lineofsuccession.co.uk/ and https://towerbridge.dave.org.uk/ (you’ll need to look at the source to see it).

I’ve written the module as a Moo role, which means it should be usable in Moose classes too. To add JSON-LD to your class, you need to do three things:

  • Add the role to your class
  • Define a method called json_ld_type() which defines the type of JSON-LD object that you want to generate (see Schema.Org for a list of types)
  • Define a method called json_ld_fields() which defines the fields that you want to include in your JSON-LD. There are a few ways to define that which allow you to do things like mapping an output field to a method of a different name. The details are in the documentation.

Your class inherits two methods from the role – json_ld_data() returns the data structure which will be encoded into JSON (it’s provided in case you want to massage the data before encoding it) and json_ld() which returns the actual encoded JSON in a format that’s suitable for embedding in a web page.

Genealogy::Relationship

One of the most satisfying parts of the Line of Succession site to write was the code that shows the relationship between a person in the line and the current sovereign. Prince Charles (currently first in line) is the son of the sovereign and Tāne Lewis (currently thirtieth in line) is the first cousin twice removed of the sovereign.

That code might be useful to other people, so it’s now on CPAN as Genealogy::Relationship. To be honest, I’m not sure exactly how useful it will be. The Line of Succession is a rather specialised version of a family tree – because we’re tracing a bloodline, we’re only interested in one parent (which is unlike normal genealogy where we’d be interested in both). It also might be too closely tied to the data model I use on my site – but I have plans to fix that soon.

Currently, because of the requirements of my site, it only goes as far as third cousins (that’s people who share the same great, great grandparents). That’s five generations. But I have an idea to build a site which shows the relationship between any two English or British monarchs back to 1066. I think that’s around forty generations – so I’ll need to expand the coverage somewhat!

But anyway, it’s there and I’d be happy if you tried it and let me know whether it works for you. The documentation should explain all you need to know.

The Line of Succession site doesn’t get much traffic yet – I really need to do more marketing for it. So it’s satisfying to know that some of the code might, at least, be useful outside of the project.

Line of Succession

I’m a republican. No… wait… come back! That’s not what I mean.

I’m a long way from being a supporter of the Republican Party. I mean “republican” in its older meaning of “someone who thinks their country should be a republic. That is to say, I’m not a big fan of the British royal family.

But while I believe that the UK should get rid of the royal family, I’m also fascinated by them. In particular, I’m fascinated by the laws that determine the line of succession – that is the list of people in line to take over the throne.

When I was a child I believed that the line of succession was a big list that had every British person’s name on it and that it would only take a single catastrophic event to propel my name to the top of that list. Later on I discovered the Act of Settlement (1701), which is the law which actually defines the line of succession (modulo a few later tweaks). I was disappointed to find that there were only a few thousand people on the list (and that didn’t include me!) and also that a lot of the people on the list weren’t British (largely due to Queen Victoria’s children marrying royalty from all over Europe).

A few months ago, I started to think about building a web site that would allow people to explore the line of succession through time. And over the last few weeks, I have build the site. It’s at lineofsuccession.co.uk. On the main page, you will see the current line of succession. And in the navigation bar is a drop-down menu that allows you to move to a few interesting data (the days that the last four monarchs came to the throne) and a date picker allowing you to choose any random date.

The code is, of course, on Github. The web app is a pretty standard Dancer2 application which really doesn’t do anything clever. Most of the complexity in an application like this is in the data gathering.

Currently I have just over a hundred people in the database. That’s most of the descendants of Edward VII (there a few lines that I haven’t completely filled out yet), but eventually I want to go back to all include all of the descendants of Electress Sophia (the person who the crown was “settled on” in the Act of Settlement). I’ve heard estimates that she has somewhere between 5-6,000 descendants. So I have a bit of work to do there!

Other than more people, I have a few other things I’d like to add to the site:

  • More names and titles People on the line of succession tend to have many titles during their lives. The data model already supports the concept of a name that is only valid on a range of dates (see the current queen described as Princess Elizabeth of York on the day before her father became king,  Princess Elizabeth when he was king, Duchess of Edinburgh when she got married and, finally, Queen Elizabeth II when she became queen. But tracking down and adding all that data is hard work.
  • Excluded people Catholics are excluded from the line of succession. And people who married Catholics were also excluded until recently. Oh, and obviously children born out of wedlock (that’s more common than you might expect in some of the more obscure branches of the modern Windsor family). Of course, people can convert to (and from) Catholicism at any time, so supporting that in the app would mean implementing some kind of “exclusions” data. But it would be good to show these people, perhaps in a dimmer font.
  • Tree views Today I added text to each person showing their relationship to the monarch. That can help a reader to visualise the family tree, but I’d like to make it more explicit. Nested lists could make it easy to see the relationships. And, later, perhaps show the whole tree using SVG.
  • Position changes Sometimes the line of succession feels a bit like the pop charts. Take Prince Harry, for example. He entered the chart at position 3 and stayed there until Prince George bumped him down to number 4 and Princess Charlotte pushed him down to 5. He’s only likely to fall further in the coming years. The same thing happened to Princess Anne, who was number 3 when she was born, but currently languishes down at number 12. I think it would be interesting to plot those changes over time.
  • Make it prettier Bootstrap does the job. It allows design dunces like me to get a reasonable-looking site up and running in no time. But it’s not very regal.

Anyway, there’s my current itch scratched. And, as in so many cases, it’s just given me more itches. But please let me know if you find the site at all interesting or useful.

Regenerating Perl School

About five years ago I ran a few training courses under the Perl School brand. The idea was simple – if you price training courses cheaply and run them at the weekend then you eliminate the most common reasons why people don’t keep their Perl knowledge up to date.

Of course, it’s not quite that simple. And I think I ran six courses before running out of attendees.

But there are still people who would benefit from getting some more up to date information about how Perl works. So I’ve decided to resurrect the Perl School brand in a new attempt to spread the Modern Perl knowledge beyond the echo chamber. I announced my plans during my lightning talk at last month’s London Perl Workshop.

This time I’m going to do it by publishing cheap books. You might remember that time I promised to write a guide to modern web development with Perl and how badly that ended up. But in the process, I learned a lot about publishing ebooks to Amazon. I even gave a talk where I suggested that Perl book publishing could become a cottage industry. And that’s what I’m currently aiming at.

I’ve made a start already. just before the LPW I published a book called Perl Taster which aims to take people through their first two hours of learning Perl. It’s cheap enough (and small enough) that people can give Perl a try without investing too much money or time.

But my plans don’t stop there. I have ideas for half a dozen other books that I can publish over the next few months. Basically, if you’ve one of my training courses over the last five years then you can expect a (short!) book based on that course to appear at some point during 2018. Currently my plans include books on:

  • Moose
  • DBIx::Class
  • Modern Core Perl
  • Dancer2
  • Testing

Obviously, there are plenty of other books that could be written this way. And I don’t want to have to write them all myself. Which is where you come in. Is there a Perl-related subject that you’re an expert on? Would you be interested in writing a book about it?

I’m offering to help people publish Perl books. If you can write a book using Markdown, then let me take care of the complicated bits of turning your text into an e-book and getting it published on Amazon (and, perhaps later, other e-book platforms).

So, over to you. What do you want to write a book about.

p,s. At some point I should probably finish the e-book I was writing about publishing e-books.

London Perl Workshop Report

Lightning Talks Preparation at the LPW 2017

(Photo above by Chris Jack)

Last Saturday was the annual London Perl Workshop. I should write up what happened before I forget it all.

I arrived at about 8:30 in the morning and was able to check in quickly – collecting a bit of swag which included a free t-shirt as I was a speaker. I then made my way up to the main lecture theatre in order to see Katherine Spice welcoming people to the day on behalf of the new team of organisers. After that headed off to the smaller lecture theatre to set up for my tutorial. There were a few differences from previous years. Firstly, I was giving a completely Perl-free tutorial (about on-page SEO techniques) and secondly, I had been moved out of the tutorial track and into one of the main talk tracks. As a side effect of that second change, I was also asked to trim my talk from my usual two hours to a more “talk-like” eighty minutes.

The talk seemed to go well. I got some interesting questions and a few people came up to me later in the day to tell me they had found it interesting useful (sometimes both!) The slides to the talk are available on SlideShare: Web Site Tune-Up – Improve Your Googlejuice.

Following that, I had time to see one talk before the coffee break and I chose Why learning a bit of Crypto is good for you‎ by Colin Newell. Colin gave a good (if, necessarily rather shallow) explanation of how learning a small amount of cryptography can help you improve the security of your systems.

Then it was was the morning coffee break. For the past few years, this break has traditionally included cakes which were supplied by a sponsor. When that didn’t look like happening this year, organiser Neil Bowers (with a gentle nudge from Leon Timmermans) came up with the idea of a community bake. And that’s what happened. A number of attendees baked cakes for us all. I had one of Neil’s blueberry muffins and it was lovely.

There was a slight change in the schedule after the coffee break. Matt Trout was unable to be at the workshop so, at the last minute, JJ Allen stepped in and gave his talk To delete or not to delete, that is the question‎, which was about some impending data protection laws which will affect all businesses. I stayed in the same room to see Neil Bowers explain The PAUSE Operating Model‎ and then JJ returned to talk about something completely different – Perl and Docker, sitting in a tree‎.  JJ’s company, Opus VL, have released some of their Docker infrastructure code to CPAN and I’m sure many people will find it useful.

Then it was lunchtime. I bought a sandwich from the university’s cafe and sat in the foyer talking to various friends who walked past.

I started the afternoon watching Paul Evans on ‎Devel::MAT updated‎. Devel::MAT is a development tool which aims to do for memory analysis what Devel::NYTProf does for profiling. It looks very useful. That was followed by Julien Fieggehenn’s talk Turning humans into developers with Perl‎. Julien doesn’t just train people in Perl, he acts as a mentor for them for a couple of months when they join his company, so he was able to talk in some detail about much wider issues than just choosing which topics to cover in a training course.

Talking about wider issues, I then saw Tom Hukins’ talk Development: More than Writing Code?‎ Tom is, of course, right that there’s more to being a good developer than just writing good code. This is a topic that I’m thinking of developing a training course on. Tom was followed by Paul Johnson giving good advice on Modernising A Legacy Perl Application.

The afternoon coffee break included some professionally baked pastries. They were also lovely, but don’t think they were appreciated quite as much as the morning’s community versions.

After the coffee break, we all gathered in the main lecture theatre for the plenary session. Ann Barcomb spoke about Fifteen Years of Contributing Casually‎. Ann was once a Perl developer. I first met her at the first YAPC::Europe in London in 2000 and she was then part of the organising team for the second YAPC::Europe in Amsterdam in 2001. But since then she has become a researcher into the sociology of the open source movement. You can read a lot of her research on her web site. Her talk illustrated her findings with some personal anecdotes about her own casual contributions to the Perl community. Everyone seemed to find it fascinating and the Q&A at the end of the talk showed every signs of turning into a full-scale discussion. On a personal level, it was great to catch up with Ann again about fifteen years after we had been in the same room together.

And then there were the lightning talks. They were their usual mixture of intriguing and entertaining. Mark Keating (enjoying his first LPW that he wasn’t organising) implored us to get involved in the Enlightened Perl Organisation. I announced a plan to publish more Perl books (of which, more later). I was particularly impressed by Kenichi Ishigaki who flew in from Japan just to give a lightning talk about his module Perl::PrereqScanner::NotQuiteLite.

After that, there were a few closing words from Neil Bowers and, in another innovation brought in by the new organisers, drinks were served on site rather than in a local pub. Of course, some people went off to a local pub after that as well.

As always, it was a great day. The new organising team seem to have hit the ground running and produced an impressive workshop. My thanks to the organisers, the volunteers, the speakers, the sponsors and all of the attendees.

I’m already looking forward to next year’s workshop.