Skip to content

Instantly share code, notes, and snippets.

package MusicPref;
use Moose;
use namespace::autoclean;
has 'name' => ( is => 'ro', isa => 'Str' );
package Character;
use Moose;
use namespace::autoclean;
has 'name' => ( is => 'ro', isa => 'Str' );
has 'music_prefs' => ( is => 'rw', does => 'KiokuDB::Set' );
@xsawyerx
xsawyerx / author-pauseid.pl
Created August 2, 2011 05:42
MetaCPAN::API example
use MetaCPAN::API;
my $mcpan = MetaCPAN::API->new();
my $author = $mcpan->author( pauseid => 'XSAWYERX' );
@xsawyerx
xsawyerx / dancer1-design.txt
Created June 28, 2012 22:51
Dancer design graphs
.---------.
.----------.----------| Handler |--------.--------.
| | | '---------' | |
| | | | | |
| | | | | |
v v v '-> v v
.-----. .-----. .-----. .------------. .------. .-------.
| App | | App | | App | | Serializer | | Hook | | Route |
'-----' '-----' '-----' '------------' '------' '-------'
@xsawyerx
xsawyerx / datetime.pl
Created July 13, 2012 20:38
Finding Friday the 13th
use strict;
use warnings;
use DateTime;
my $dt = DateTime->new(
day => 13,
year => 2012,
);
my $count = 0;
@xsawyerx
xsawyerx / async_response.pl
Created October 31, 2012 14:31
using send_file for full non-blocking async fork w/ condvars
# this function lets you run code in a fork
# and use a condvar on it to get the data
# and return it to the client in JSON form, all non-blocking and async
# based heavily on a trick by Assaf Gordon
sub async_response (&) {
my $cb = shift;
send_file(
\'noop',
@xsawyerx
xsawyerx / recur_def_promise.pl
Last active December 14, 2015 21:39
Recursive deferred promises: sometimes you need to run a set of actions consecutively without knowing how many actions exist. An example would be running an arbitrary number of commands one after the other. You want to be able to add more commands to the array without having to add another explicit deferred promise. This code shows how to recurs…
use strict;
use warnings;
use AnyEvent;
use AnyEvent::HTTP;
use Promises 'deferred';
my @urls = ( 'https://ddg.gg', 'http://dyndns.org', 'http://metacpan.org' );
my $cv = AE::cv;
my $cb; $cb = sub {
use v5.10;
use MetaCPAN::API;
use Data::Dumper;
use List::AllUtils qw(min max);
use DateTime;
use DateTime::Format::ISO8601;
my @score_label = qw(
Abysmal
Poor
@xsawyerx
xsawyerx / ratings
Created March 2, 2014 14:48
MetaCPAN Ratings
MetaCPAN::API::Rating {
Parents Moo::Object
public methods (9) : author, date, details, distribution, helpful, new, rating, release, user
private methods (1) : _known_fields
internals: {
data {
author "PLACEHOLDER",
date "2014-03-02T12:20:07",
distribution "Moose",
rating 4.9,
@xsawyerx
xsawyerx / Eg1.pl
Last active August 29, 2015 14:08
Example Dancer2 setup
# app.pl:
use MyApp::Web;
use MyApp::Web::API;
use Plack::Builder;
builder {
mount '/' => MyApp::Web->to_app;
mount '/api' => MyApp::Web::API->to_app;
};
#!perl
use strict;
use warnings;
use IO::All;
use IO::All::LWP;
use Web::Query;
local $| = 1;
wq('http://podbay.fm/show/536258179')