This weekend I released two versions of
Net::AMQP::RabbitMQ on CPAN: 0.007000 and 0.007001.
The first version was the culmination of some major refactoring in how Perl types were inferred into C and AMQP types in headers, and then also adding a bunch of previously-unsupported AMQP header types into Perl.
The second version was fixing an oversight where
timestamp types in headers weren’t supported. I also added a
manual_tests directory which is where I will add some manual tests as I do some of those. There is a test where I verify dead-letter queue functionality that helped me verify that
x-death headers were working properly now.
The primary reason why this is huge is because the special
x-death headers are now supported. Not only that, but in the event that you had a non-Perl program publishing to your queue with headers, you may have had compatibility issues with the header types that would cause to have to kluge.
As of now, the new version – 0.007001 – isn’t live, but if you search for the module on CPAN you should find the latest published version.
If you notice any issues, let me know by going to the official github repo and filing an issue.
Today I got tests done, and I kinda abandoned
Error.pm for exception handling. I switched over to using
Try::Tiny since it looks like there are known issues with Error.pm in more modern frameworks like
Moose. I’m going to try to avoid using ##no critic as much as I can, but I had to use it twice in my
ModExec::Exception class since I wanted to include the sugar functions from
Try::Tiny, and since I want to use
die() in my throws to keep the object intact.
Here’s tonight’s changeset: http://tinyurl.com/nuzvnzt
Next up is the base class,
In re-factoring ModExec, I have started with the exceptions. I’m debating how I used to do them. When I first started I used
Error qw/:try/ and
Error::Simple for exceptions. I still think I will, it looks like it’s still being well-maintained by Shlomi Fish (see here).
I think that the piece I will bite off first is to get some test coverage around my exceptions and add documentation. They’re not much more than what you get with
Error::Simple, but there’s some stuff in there for stack dumps and things like that.
Goals for this first pass are:
- Pass a
`perlcritic -3` for all exception code
- Add POD for all exception code
- Add a test for at least some of the methods (more tests will be added later)
Before and After
Here are some GitHub links:
I like repeatable tests. The #1 benefit of repeatable tests is that they’re repeatable. This also means they’re less vulnerable to data changes (e.g. this test depends on this product record remaining unchanged) and don’t pollute your environment. There are two ways that I think you can make your tests repeatable, and I think both of them are equally valid, and each should be used in their appropriate time:
- Creating and tearing down fixtures
- Using some sort of mocking framework to force a repeatable result from an up-stream dependency that is not what you’re trying to test
Continue reading Gist of the Day: Test::MockModule for Repeatable Tests!
First, I suppose I should apologize for two days of silence. I am currently going through a major life transition, so things could get a little spotty for a while. I haven’t forgotten about you. I actually have had a couple of days where my experiment for the Gist of the Day failed, and I couldn’t get something working in time to put it up.
Today, however, I do have something for you!
Today we are going to cover two topics very briefly (as usual): 1) how do you factor files you wrote into your tests, and 2) how do you write your code with testing in mind (which you should). Continue reading Gist of the Day: How to Test a File You Wrote!
In programming you will commonly see abstraction layers. Say, for instance, you wanted to have a program to take some arbitrary data format and load it into your data. We’ll call it product feeds (just because some people like relevant examples). So, you want to pull in product data from various different web sites and vendors to list some products on your site. Now if you have ever done this task before then you’re already thinking “jeez, what a pain in the ass it is to get everybody to use the same format!” If you’ve done this task before then you’ve probably already dabbled in this type of abstraction. In Perl – my go-to language (since I arbitrarily prefer it) – this usually results in dynamically loading a “driver” class based on the data format which is likely vendor-specific. This makes it easy/easier for you to allow each data source to have its own format while using them all in the same way.
If you were to pick a Design Pattern for this, you would do well to choose a Factory pattern. In Perl, since you have so much dynamic leeway, you don’t need to go with a pure Factory pattern here, but what you end up with I think is most certainly in keeping with a factory pattern.
For this Gist, I will demonstrate three common ways to get from knowing which class you need to getting that class:
Continue reading Gist of the Day: There’s More Than One Way to Switch Your Class!
Mojolicious is a fun module/framework/thing for me. How do I love Mojolicious? Let me count the ways (sorry Shakespeare):
- Mojo has ridiculously few dependencies, especially when compared to other web frameworks
- Mojo brings web servers (morbo and hypnotoad) with it
- Mojo does MVC, or doesn’t do MVC, whatever I want to do
- Mojo has templates, and they’re outstanding
- Mojo does routes very simply, which is badass
- I can write an entire web application in only one file (though it could get big and may not be advisable) using Mojolicious::Lite
- Mojo has helpers which are actually helpful
- Mojo is crazy fast, so fast that if there is a performance problem I’m pretty sure it’s me
- The more I use Mojo, the more I find cool stuff that it can do Continue reading Gist of the Day: Mojo Merging Hashes
I am very sorry that I missed posting this yesterday, I kinda got crazy sleepy and went to bed shortly after getting home from work.
AS PROMISED, however, this next Gist is the SL4A Android component. This program gives you two buttons: “Process Queue” and “Exit the program!” With these two buttons you can either process a message from the queue (see previous post) or exit the program. Processing the queue involves sending an SMS message and then repeating the message with TTS. Continue reading Gist of the Day: Using Mojo, Mongo, and SL4A to send SMS Messages (2 of 2)
I got a little bored with what I had been posting (I suspect you did, too), so I’m doing something neat. I’m going to write a full (though limited) program for you. Here are the user stories (if you don’t know what user stories are, see here before continuing):