Back on the Moose Track

Well with my last post I managed to get a little closer to my original goal of selecting a 'Character Class' after I have selected a 'Race' as the image below explains

add.jpg

I sometimes have a Hobbit (well Halfling in A D&D) of doing that.

Well in this post I centralized all of the 'Race' rules under one namespace and so I though I might as well do that for 'Character Class' rules as well.

So for each of my 'Character Classes' I could just add a new role like this

Writing Non-Blocking Applications with Mojolicious: Part 3

This the the third part in an on-going series about using Mojolicious to write non-blockging applications (with an eye towards the web, obviously). In part 1 I demonstrated the how it can improve the number of requests/clients served when the application uses high-latency backends (in that case a database). In part 2 I showed how each request can be sped up when that request needs multiple resources from a high-latency service (e.g. external web services).

In each, I showed a blocking example, then a non-blocking example. I then gave the usual warning that you had to use a Mojolicious server for the nonblocking version. While its true that you need a Mojolicious server to get the benefits of the nonblocking architecture, in this post I will show how with a little care in construction, you can build your application so that it will run correctly on any supported server and the nonblocking benefits will be evident where possible.

Is Perl really short of newbies?

Before writing about the main topic, let me tell you a little bit about myself, my peers & why I am writing this blog post etc.

Perl and Me, Part 7: The Most Powerful Weapon Which You Can Use to Change the World

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

This week we meander around the topic of education hoping to come to a point about Perl.

So far we’ve learned that I’m an English major, that Perl has a lot of linguistics baked into it, and that (at least in my opinion) creativity is good for programmers.  What does all that mean?  Well, for me, one of the things it means is that I lack some of the computer science background of my peers.  I never had to take a class in compiler design, for instance.1  In fact, there’s a lot of stuff that CS majors had to learn that I never did.  Oh, sure—I picked some of it up along the way.  But it’s still true that when I read certain very technical programming blogs (like Jeffrey Kegler’s excellent articles on Marpa), I have to skim over a bunch of parts.  But I also have an analogy I’m fond of breaking out:

You don’t have to understand how the internal combustion engine works in order to drive a car.

Keep Calm, Roll on.

In my last post I left off with asking myself a whole lot of design questions after I decided to centralize most if not all of my 'Game/Business Rules' into 'Roles' under the logical namespaces. In the end I can just live with what I came up with even if there is some duplication of code I don't think I am in anti-pattern land yet.

kkrac.jpg

Well now I think I will get back on track from where I left on with this post and that is filtering out 'Player Classes' once I select a 'Race'. I had the basics done but now there are a few more little things to add in and we will start with a cool one racial adjustment.

Some races get an adjustment to their ability scores and these adjustments are used when selecting a 'Class' So an 'Elf' with '8' dexterity roll get a +1 so they will be able to become a thief.

Support the Perl QA Hackathon 2014 in Lyon

Since it was announced in November 2013, Laurent Boivin and I have been busy with the organization of the Perl QA Hackathon 2014, securing venue, accommodation, catering, sponsors, invitations, etc.

During this seventh edition, as usual, the participants will be giving their time, knowledge and experience to the Perl community for four days, hacking and arguing about QA (quality assurance) and CPAN toolchain. In return for their time and valued experience, we want to make this event as cheap as possible for them to attend, by covering their travel, accommodation and food to the best of our abilities.

ZMQ::FFI and FFI::Raw

A few months ago I released ZMQ::FFI, zeromq bindings for Perl that use FFI::Raw instead of XS. There's been some interest, so I thought I would write a short post to announce the module beyond the zeromq mailing list.

In another post I'll discuss FFI::Raw itself, what it currently provides, as well as some advanced use cases that came up during the development of ZMQ::FFI. If reverse depends on metacpan is anything to go by, it seems many people aren't aware of this module. In fact, at the time of this writing ZMQ::FFI is the only module using it:

ffi-raw-reverse-depends.png That's a shame, as it's a terrific module which finally makes FFI in Perl feasible. It effectively eliminates the need for XS in many cases, and it's sufficiently baked to be considered "production ready."

Tech Tip: Opening a file for read/write without clobbering it.

The Tip

perlopentut gives several options for opening a file for read and write, and I opted to use '+>' for Maniac Downloader, but as it turned out, it caused the existing file to be clobbered (= its length to be set to zero and all of its contents deleted).

After asking on Freenode's #perl channel, we reached this solution for opening a filehandle so that: 1) it will be opened for read/write. 2) it can open both an existing file or create a new file that does not exist. 3) If the file exists, its contents will be retained, and it won't be clobbered. and 4) it will overwrite existing contents, and not append everything at the end of the file.

The code is as follows:

Rule Role's or Role's Rule?

In my last post I used a role called 'MaxLevel' to define a small set of game rules that define both the 'Player Classes' and 'Maximum Player Level' a race can obtain. That got me thinking that perhaps I could improve my 'Race' class a little by getting rid of the 'ability_mins' attribute and moving it into a role.

player-character-deaths-d-amp-d-dungeons-dragons-character-d-demotivational-poster-1242486691.jpg

After a little more head scratching what I decided on was to reorganize my namespace a little so all the 'Game Rules' or 'Business Rules' if you like will be in logical places. So all rules for a 'Race' are in its folder and all 'Races' have the same set of rules but with slightly different code.

So step one I converted my 'ability_mins' into a role like this.

A repl site for a lot of languages

repl.it

Source code available on GitHub. Who will add Perl support to it?

Testing Random Dice Rolls

I've decided to rewrite my Perl testing course from scratch and hit upon an interesting problem that is outside of the scope of the course, but is a perfect fit for this site: testing dice rolls. I have the the following function as part of a student lesson in the course:

Regular Expression Library

Regular Expression Library :

[From my blog.]

A Class Without Class

Well in this entry I am going go to the next step and this time enter a 'Race' into the instantiation arguments of my Creator and it should then give me a list of 'Player Classes' that are available to the entered Ability rolls and Race selection.

Of course I will still have to the same checks for 'Grot' and 'Race' as I do not want someone to sneak something in by simply adding a 'Race' to the mix.

0227_LARP-592x323.jpg

So like my LARP party above lets start with a new code in my 'Creator' class's 'BEGIN';

Lexical closures with END blocks warn, but Just Work

I was just impressed by the awesomeness of Perl. More testing revealed to me that "use 5.018" does not invoke "use warnings", which dampened my enthusiasm a little. But Perl is still pretty awesome. Here's the situation.

I write lots of Prima GUI applications. In this one (a presentation if you can believe that), I wanted a timer so I could see how long my talk was going. I had just run through part of my lecture and meant to check my time before closing (the clock is discretely placed in a separate window), but forgot to check before quitting the talk. Frustrated, I decided that I wanted my program to print the talk duration when it was finished.

My normal approach would have been to declare a file-scope lexical that gets initialized at startup, and refer to that in my END block. But instead, I decided to embed the END block within the initialization function itself.

Tie::File don't while(<>)

Consider the common case where you want to take a text file and walk it doing various operations such as stripping whitespace, looking for duplicates, sorting or other common operations. I was recently asked to work on a program where part of the process is 'cleaning' uploaded files before doing other things with it. This process was over 40 lines of subs opening old and new filehandles, doing the standard while(<>) {} and then renaming new file to old file. If you find yourself wanting to do something you would normally do on an array, but on a file and often in place, consider Tie::File before while()ing away at it. The documentation has many examples and there are several examples on the web including at Perl Monks. In this case I was able to whittle this down to this:

TPF Grant Progress Report: January 2014

This past May, The Perl Foundation awarded a grant to fund development of a couple features in Pinto. Pinto is a robust tool for curating a private repository of CPAN modules, so you can build your application with the right modules every time. This is my fourth progress report on that work.

I've done quite a lot of work on Pinto the last few weeks. And today, I pushed a development release to CPAN that has a lot of really cool features and improvements. However, none of this work is tied to the TPF grant.

But now the backlog is cleared up a bit, so I hope to finally finish off the grant work. Look for another update next month.

PS: I'll have a lot more to say about the new Pinto features when I make a production release in a week or so. For a sneak peek, look at the change log.

A Race to the Finish

Well in my last post I made use of the visitor pattern so sort out 'Grot' characters at an early stage. My next challenge is to set the race of my 'Character' from one of the ones below.

RPG_Races_proportions_by_Artigas.jpg

Well not all of these just the original 7 A D&D races. I could try my visitor pattern again but part of what I want to build into this system is the ability to eventually expand into the odd miss-mash of races above. So I could go back and attempt to do this with parametrized roles like I tried to do with Grot character as in this post but what I really want is to load in my 'Ability' rolls and then have it tell me what 'Race' I could be rather then attempting to load all those roles.

I guess I could use a simple given when in sub on my 'Creator' class but then I would have to recode things if I added a new 'Race' into the mix.

PHP puzzle

So I've decided to make a little PHP puzzle.

The following program contains 3 test cases that you need to make pass. To do that, you should replace XXX in the assignments to $a, $b and $c by the right magic values.

Want to hire me, or Dave Cross or Michael Schwern?

So far our company has been growing quickly and I'm quite pleased with that. I'm doubly pleased to announce that Dave Cross and Michael Schwern have joined us as trainers and consultants. Read the announcement here.

perlsphere.net: Static since last Friday

Anyone know what the problem is?

perlsphere.net

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.