Sign in to PrePAN


User's Modules

Chef::Knife A thin wrapper around the knife cmd line tool

Is this a good idea?

kablamo@github 0 comments

Test::Mode Am I in test mode?

Sometimes I want my code to behave differently if its running inside a test. I could create options for the behavior but I'd have to set them in every single test.

Examples where this might be useful:

  • I may not want to hit an external service from inside a test
  • I may want to hit the test version of the external service from inside a test
  • I might want to use a different database thats preloaded with test data.
  • I might want to disable caching
  • Don't print messages to stdout in test mode
  • etc

This is probably not a problem you have if you use something like Test::Class::Moose.

The implementation would look like:

package Test::Mode;
use strict;
use warnings;

use List::AllUtils qw/any/;
use Exporter::Shiny qw/test_mode/;

sub test_mode {
    return 1 if any {$_ eq 'Test/'} keys %INC;
    return 0;

kablamo@github 3 comments

Params::Required Simple sugar for checking method parameters exist

The implementation is very simple and short. It just croaks if the listed keys have no defined values in the params hashref.

I went back and forth a bit on whether the check should be for 'defined' or 'true'. I landed on 'defined' because 0 is sometimes a valid value.

Params::Validate is excellent and has very similar functionality. But in practice, I never use any of the power of Params::Validate. I always just check if the variable is defined and leave it at that. So it irks me that I have to type the extra => 1 all the time.

This is clearly not an order of magnitude improvement. Its just a tiny bit of sugar for the most common scenario.

Here some more traditional ways to check for required parameters.

sub attack {
    my ($self, %params) = @_;

    croak "weapon is required for attack()" unless $params{weapon};
    croak "battle_cry is required for attack()" unless $params{battle_cry};
    croak "shield is required for attack()" unless $params{shield};

    # attack

# shorter, easier to extend, but harder to read
sub attack {
    my ($self, %params) = @_;

    foreach my $key (qw/ weapon battle_cry shield/) {
        croak "$key required for attack()" unless defined $params{$key};

# powerful and pretty short but still a bit verbose
use Params::Validate;
sub attack {
    my $self = shift;

    validate @_, {
        weapon     => 1,
        battle_cry => 1,
        shield      => 1,

    # attack

kablamo@github 9 comments

Net::CurlCmd Convert HTTP::Request objects to curl commands you can run on the command line

This would be useful for debugging and documenting REST APIs.

Any better ideas for namespace?

kablamo@github 4 comments

String::CamelSnakeKebab camel case, snake case, kebab case

Camel-Snake-Kebab is a Clojure library.

Has anything like this been done already? I could only find String::CamelCase.

kablamo@github 2 comments

vCard and vCard::AddressBook Read, write, and edit vCards

I have recently submitted a large number of fixes and improvements for Text::vCard and Text::vCard::Addressbook. Those fixes have not yet been released to CPAN but that will happen soon.

I have also written a new and hopefully easier to use user interface built on top of those modules. If there are no objections I would like to use vCard and vCard::AddressBook. I realize this is a bit bold taking a top level namespace, but here is my thinking:

  1. This module aims to be the canonical Perl vCard library. I have done quite a bit of work to improve compatibility with RFC 6350 and fix encoding issues.

  2. Alternative namespacing ideas came out weird: Text::vCard::Simple and Text::vCard::Simple::AddressBook? or Text::vCard::Simple::vCard and Text::vCard::Simple::vCard::AddressBook? or Text::vCard::Simple and Text::vCard::Addressbook::Simple?

I also welcome feedback on the user interface.

kablamo@github 1 comment

Locale::CallingCodes Lookup country calling codes using country names

Data source:

I will keep the data up to date periodically using a script to parse that wikipedia page.

kablamo@github 1 comment

Plack::Middleware::Redirect Perform 301 redirects based on regexps

This module performs a redirect (HTML status code 301) for urls which match a list of regular expressions. The redirect happens before $app is called which means $app is completely bypassed if a url matches.

Plack's PATH_INFO environment variable is the part of the url that looks like '/path/to/a/resource'.

The QUERY_STRING env var is the part of the url that looks like ?rubbery='octopus'&fluffy='bunny'.

Currently the regexps are only applied to PATH_INFO. The QUERY_STRING is always appended unaltered to the end of the new redirected url. I guess there should be a way to configure that. Or perhaps the regexp should apply against both PATH_INFO and QUERY_STRING.

Its a little weird that url_map is a Hash inside an ArrayRef. But when you have a list of 20 redirects, I feel the extra punctuation gets in the way of readability and there are several other Plack middleware modules that do this.

kablamo@github 3 comments

IPC::Tail Print the live output of a command to a filehandle

This module will print the output of a command. Its key feature is that it doesn't wait for the command to finish before beginning to print the output. It prints the output as it happens. You can pass it a filehandle so it knows where to print to.

My biggest concern is the name? Its not really tail, its more like tail -f. The -f in tail terminology stands for 'follow'. Perhaps it should be IPC::Tailf or IPC::TailFollow or IPC::Follow or IPC::LiveOuput or IPC::PrintCmd?

So far this is vaporware. I hope to implement this using IPC::Run.

kablamo@github 2 comments

Devel::StackTrace::Always Force a configurable stacktrace for all warn()s and die()s in your program

This module is inspired by Carp::Always. It is meant as a debugging aid. It forces a script to print a stacktrace when warn()ing or die()ing.

The advantage this module has over Carp::Always is that it allows the user to filter items out of the stacktrace. This is useful in larger applications where stacktraces can get very long and where you often want to filter out parts of a stacktrace. For example a Plack application usually doesn't need Plack to be part of the stacktrace.

Ideas for the future

  • Shorter module name (alias) for use on the command line
  • A prettier more readable default stacktrace output?
  • Configurable stacktrace output using sprintf or something?
  • Colored output?
  • An easy way to toggle showing all stacktraces vs hiding ignored parts of the stack
  • Plugins on CPAN which ignore parts of the stack from certain applications like Plack, Moose, or Catalyst? For example Devel::StackTrace::Filter::Plack, Devel::StackTrace::Filter::Catalyst.
  • Allow setting configuration via a file. Like Data::Printer does.
  • Split out some code into Devel::StackTrace::Filter? Perhaps this should be 2 modules: Devel::StackTrace::Filter and Devel::StackTrace::Always.

kablamo@github 2 comments