Skip to content

Instantly share code, notes, and snippets.

View pjlsergeant's full-sized avatar
🙇‍♂️
I don't really have time for this anymore

Peter Sergeant pjlsergeant

🙇‍♂️
I don't really have time for this anymore
  • Bangkok, Thailand
View GitHub Profile
my $c = {
foo => {
bar => {
baz => 123
}
}
};
package CatalystX::RequestRole::StrictParams;
use Moose::Role;
use Carp qw/croak confess carp cluck/;
=head1 NAME
CatalystX::RequestRole::StrictParams - Insist users specify HTTP method for form parameters
=head1 DESCRIPTION
@pjlsergeant
pjlsergeant / gist:2556415
Created April 30, 2012 08:02
Moose Point Class
package Point;
use Moose;
has 'x' => (isa => 'Int', is => 'rw', required => 1);
has 'y' => (isa => 'Int', is => 'rw', required => 1);
# And then later, somewhere else...
my $point = Point->new({ x => 3, y => 5 });
$point->y( 7 );
@pjlsergeant
pjlsergeant / gist:2556399
Created April 30, 2012 08:01
Concise map-reduce in Perl
use strict; use warnings;
use List::Util qw(reduce);
use File::Slurp qw(read_file);
# Given a list of filenames, return a hash of each word and the number of times
# it occurs.
sub word_count {
reduce { $a->{$b}++; $a } {},
@pjlsergeant
pjlsergeant / gist:2556380
Created April 30, 2012 07:58
Simple linked lists example
use strict;
use warnings;
use Test::More;
use constant NEXT => 0;
use constant VALUE => 1;
sub make_list {
my ( $head, @tail ) = @_;
return [ undef, $head ] unless @tail;
sub multiply {
my ( $x, $y ) = @_;
return $x * $y;
} eg {
is( $_->( 2, 5 ), 10, "2 and 5 equal 10" );
}
@pjlsergeant
pjlsergeant / gist:2309525
Created April 5, 2012 09:36
CatalystX::PSGIApp
package CatalystX::PSGIApp;
use strict;
use warnings;
use Catalyst;
=head1 NAME
CatalystX::PSGIApp - Get a psgi_app in a unified way across different Catalyst versions
package CatalystX::PSGIApp;
use strict;
use warnings;
use Catalyst;
sub psgi_app {
my $class = shift;
my $target = shift;
around 'simple_request' => sub {
my ( $original_method, $self, $request, @args ) = @_;
if ( $self->http_debug ) {
note "Request:";
note $request->as_string;
}
my $response = $self->$original_method( $request, @args );
# Table parsing, old friend... We have spent many long evenings together,
# working through your broken tables, talking about your issues with
# implicit thead elements, and your quirky tr/th heuristics. But ... but
# but it's time for us to move on. We can't keep doing this. It's not you,
# it's me...
#
# I've ... I've met someone new. She's beautiful, she's modern, and she's
# elegant. She's logical, she's clean, and she's well-structured, if you
# know what I mean...
#