Skip to content

Instantly share code, notes, and snippets.

View schwern's full-sized avatar

Michael G. Schwern schwern

View GitHub Profile
@schwern
schwern / nl_pipe.plx
Created January 22, 2011 13:47
Test showing that the line ending is lost in a pipe on Strawberry Perl 5.10.1.4
#!/usr/bin/env perl
use strict;
use warnings;
use IO::Pipe;
my $pipe = IO::Pipe->new;
if( my $pid = fork ) {
print show_eol("From parent\n"), "\n";
@schwern
schwern / Capture.pm
Created March 4, 2011 16:13
Capture dancer logs for testing
package Dancer::Logger::Capture;
use strict;
use warnings;
=head1 NAME
Dancer::Logger::Capture - Capture dancer logs
@schwern
schwern / gist:858194
Created March 7, 2011 07:38
dancer_request example
dancer_request( GET => "/", { params => { foofer => 54321 } }, sub {
is params->{foofer}, 54321;
});
sub dancer_request {
require Dancer::Request;
require Dancer::SharedData;
my $method = shift;
# What's best practice for setting up many sites with the same handlers
# but different configs?
#
# Example, having lots of surveys each under a separate /<survey_name>
# like /<survey_name>/login and /<survey_name>/questions
use Dancer;
my @surveys = get_surveys;
use Test::More import => ["!pass"];
use Dancer ':moose', ':tests', ":syntax";
my @keywords = (qw/before after pass/);
plan tests => scalar(@keywords) + 2;
foreach my $symbol (@keywords) {
ok( !exists( $::{$symbol} ), "symbol `$symbol' is not exported" );
}
@schwern
schwern / num_github_issues
Created March 10, 2011 14:21
Get the number of issues from a github project
use Net::GitHub::V2::Issues;
use URI;
# Examples:
# http://github.com/schwern/test-more/tree/master
# http://github.com/sukria/Dancer
sub num_github_issues {
my $url = URI->new(shift);
return unless $url->host =~ m{\.?github.com$};
@schwern
schwern / 03-server.t
Created March 12, 2011 09:25
Dancer::Session::Cookie broken against Dancer 1.3014
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More import => ["!pass"];
plan skip_all => "Test::TCP required" unless eval {
require Test::TCP; Test::TCP->import; 1;
};
my %moose;
sub init_moose {
require Any::Moose;
Any::Moose->import('::Util::TypeConstraints');
{
no strict 'refs';
my $moose = any_moose('::Util::TypeConstraints');
$moose{class} = $moose;
$moose{find_or_parse_type_constraint} = \&{$moose."::find_or_parse_type_constraint"};
@schwern
schwern / gist:879481
Created March 21, 2011 14:00
Method::Signatures performing the MooseX::Method::Signatures synopsis
{
package Foo;
# use Mouse;
use Moose;
# use MooseX::Method::Signatures;
use Method::Signatures;
method say (Str $msg) {}
@schwern
schwern / gist:889773
Created March 27, 2011 23:54
Complete list of new modules between 5.6.0 and 5.8.1
Attribute::Handlers
B::Concise
CGI::Util
Class::ISA
Devel::PPPort
Digest
Digest::MD5
Encode
Encode::Alias
Encode::Byte