Skip to content

Instantly share code, notes, and snippets.

View bigpresh's full-sized avatar

David Precious bigpresh

View GitHub Profile
@bigpresh
bigpresh / app output
Created February 15, 2011 22:48
Dancer cookies test case
[davidp@supernova:~/tmp/dancer-multicookies]$ perl app.pl
>> Dancer 1.3010 server 25291 listening on http://0.0.0.0:4002
== Entering the development dance floor ...
[25291] debug @0.003111> [hit #1]Cookies: {
"dancer.session" => bless({ name => "dancer.session", path => "/", value => ["123, wtf"] }, "Dancer::Cookie"),
} in /usr/local/share/perl/5.10.0/Dancer/Plugin/DebugDump.pm l. 19
@bigpresh
bigpresh / gist:828519
Created February 15, 2011 23:31
Supporting comma-separated cookies...
diff --git a/lib/Dancer/Cookies.pm b/lib/Dancer/Cookies.pm
index 15735fe..dd4992d 100644
--- a/lib/Dancer/Cookies.pm
+++ b/lib/Dancer/Cookies.pm
@@ -23,7 +23,7 @@ sub parse_cookie_from_env {
return {} unless defined $env_str;
my $cookies = {};
- foreach my $cookie ( split( '; ', $env_str ) ) {
+ foreach my $cookie ( split( /[,;]\s/, $env_str ) ) {
@bigpresh
bigpresh / i18ntest.pm
Created February 18, 2011 22:36
D::P::I18n test case
package i18ntest::I18N::en;
use base 'i18ntest::I18N';
our %Lexicon = ( hello => 'Hello' );
package i18ntest::I18N::fr;
use base 'i18ntest::I18N';
our %Lexicon = ( hello => 'Bonjour' );
package i18ntest;
@bigpresh
bigpresh / GitHubPullRequests.pm
Created April 26, 2011 11:59
GitHubPullRequests - not fetching default project from bot store
# A quick Bot::BasicBot::Pluggable module to fetch a count of open pull requests
# for a GitHub project.
#
# David Precious <davidp@preshweb.co.uk>
package Bot::BasicBot::Pluggable::Module::GitHubPullRequests;
use strict;
use base 'Bot::BasicBot::Pluggable::Module';
use LWP::Simple;
use JSON;
@bigpresh
bigpresh / runtimeloggerconfig.pl
Created May 3, 2011 21:33
Dead simple test case for logging configured at runtime
[davidp@supernova:~/tmp/runtimeloggerconfig]$ perl runtimeloggerconfig.pl
>> Dancer 1.3030 server 19286 listening on http://0.0.0.0:3000
== Entering the development dance floor ...
^C
# a request was made, answered with the default error 500 page
[davidp@supernova:~/tmp/runtimeloggerconfig]$ cat logs/development.log
[davidp@supernova:~/tmp/runtimeloggerconfig]$
# Nothing logged.
@bigpresh
bigpresh / results
Created May 6, 2011 20:42
Demonstrating serialisation
[davidp@supernova:~]$ curl -v http://localhost:3000/
* About to connect() to localhost port 3000 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.18.2 (i486-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.8 libssh2/0.18
> Host: localhost:3000
> Accept: */*
>
* HTTP 1.0, assume close after body
@bigpresh
bigpresh / dancerfileuploadtest.pl
Created May 27, 2011 16:35
Simple Dancer file upload test case
#!/usr/bin/perl
use Dancer;
get '/' => sub {
<<FORM;
<form method="post" action="/upload" enctype="multipart/form-data">
<input type="file" name="fileupload">
<input type="submit">
</form>
[davidp@columbia:~]$ traceroute www.perldancer.org
traceroute to www.perldancer.org (89.234.129.20), 30 hops max, 60 byte packets
1 supernova.preshweb.co.uk (10.1.10.254) 2.017 ms 2.198 ms 2.680 ms
2 cpc7-stev6-2-0-gw.9-2.cable.virginmedia.com (86.19.197.1) 10.257 ms 10.895 ms 11.194 ms
3 lutn-core-1a-ae3-2087.network.virginmedia.net (80.4.221.17) 14.239 ms 14.530 ms 14.852 ms
4 popl-bb-1a-as5-0.network.virginmedia.net (213.105.175.149) 15.164 ms 15.468 ms 15.775 ms
5 popl-tmr-1-ae4-0.network.virginmedia.net (213.105.159.2) 16.759 ms 16.913 ms 17.005 ms
6 amst-ic-1-as0-0.network.virginmedia.net (213.105.175.6) 23.652 ms 18.168 ms 18.774 ms
7 ams-001.interoute.net (195.69.144.81) 19.120 ms 18.367 ms 21.472 ms
8 ae2-0.par-gar-score-2-re0.interoute.net (84.233.190.62) 28.112 ms 28.710 ms 28.358 ms
@bigpresh
bigpresh / headertest.pl
Created August 4, 2011 21:20
Getting request headers with Dancer
#!/usr/bin/perl
use Dancer;
get '/' => sub {
return "Hi, you're using " . request->header('User-Agent');
};
dance;
240 is_deeply(
241 [ sort { $a->[0] cmp $b->[0] } @{ $response->headers_to_array } ],
242 [ sort { $a->[0] cmp $b->[0] } @$expected ],
243 $test_name
244 );
245 }
Can't use string ("Server") as an ARRAY ref while "strict refs" in use at /home/davidp/dev/github/Dancer/lib/Dancer/Test.pm line 240.