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.
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.
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.
Originally published at Perl Hacks.