Skip to content

Instantly share code, notes, and snippets.

View schwern's full-sized avatar

Michael G. Schwern schwern

View GitHub Profile
# This would work better with subroutine signatures
cases 'test all combinations', {
cases => {
set_a => sub { return( 5, 5 ) },
set_b => sub { return( 4, 6 ) },
set_c => sub { return( 3, 7 ) },
set_d => sub { return( 2, 8 ) },
},
tests => {
'equals 10' => sub {
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
use Benchmark qw(cmpthese);
my $file = shift;
my $moved = "$file.mv";
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
use Benchmark qw(cmpthese);
my $tries = shift || -3;
my $re = shift;
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use Tie::File;
use Fcntl 'O_RDONLY';
sub read_range {
#!/usr/bin/perl
{
package MyRole;
use Moose::Role;
requires "this";
sub that { 42 }
}
class:
name: Foo::Bar
attributes:
foo: { is: ro, isa: Str }
bar: { is: rw, isa: Int }
methods:
something: !method |
print "Something something something\n";
for my $name (qw/ok skip todo_skip current_test/) {
my $orig = *{"Test::Builder::${name}"}{CODE};
*{"Test::Builder::${name}"} = sub {
my $self = shift;
$self->current_test($Curr_Test);
local $Test::Builder::Level += 4;
$STORE->lock_cb(sub {
$self->$orig->(@_);
$Curr_Test = $self->current_test;
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int lengthi_log(int x) {
int length = 0;
if( x == 0 )
return 1;
@schwern
schwern / mxd_vs_ms_vs_perl.pl
Created January 10, 2011 06:21
Benchmarking MooseX::Declare vs Method::Signatures vs hand written
#!/usr/bin/perl -w
use MooseX::Declare;
class WithDeclare {
has greetings =>
is => 'rw',
isa => 'Str',
default => "Hello"
;
@schwern
schwern / mwtest.t
Created January 14, 2011 06:44
Why is this failing?
{
package SD::MW::Auth::Anonymous;
use Mouse;
use MouseX::Foreign "Plack::Middleware";
use Plack::Request;
use Plack::Response;
use CGI::Simple::Cookie;