This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
package TestApp; | |
use Mojolicious::Lite; | |
get '/one/:foo' => [ foo => [qw/bar barfly/] ] => sub { shift->render_text('hi') }; | |
get '/two/:foo' => [ foo => qr[bar|barfly] ] => sub { shift->render_text('hi') }; | |
package main; | |
use Test::More tests => 8; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojo::UserAgent; | |
use strict; | |
use warnings; | |
use 5.10.0; | |
my $ua = Mojo::UserAgent->new(); | |
my $destination = 'ws://localhost:9999/down'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
use Test::Mojo; | |
use Test::More tests => 2; | |
get '/first' => sub { | |
shift->redirect_to('second'); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MOJO_USERAGENT_DEBUG=1 perl t/mojolicious/redirect_headers.t | |
1..2 | |
NEW BLOCKING REQUEST | |
TEST SERVER STARTED (http://*:17728) | |
NEW CONNECTION (http:localhost:17728) | |
> GET /first HTTP/1.1 | |
User-Agent: Mojolicious (Perl) | |
Connection: Close | |
Content-Length: 0 | |
Host: localhost:17728 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# put.pl | |
# This works : | |
# ./put.pl daemon | |
# mojo get --method PUT --content 'foo' --header 'X-Disk: /tmp' http://localhost:3000/here | |
# This does not : | |
# ./put.pl get --method PUT --content 'foo' --header 'X-Disk: /tmp' /here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# put.t | |
use Test::More tests => 3; | |
use Mojolicious::Lite; | |
use Test::Mojo; | |
$ENV{MOJO_MAX_MEMORY_SIZE} = 2; # Force temp files. | |
$ENV{MOJO_TMPDIR} = "/nosuchdir"; # test setting tempdir dynamically |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Linux::Inotify2; | |
my $filename = $ARGV[0] or die "need a filename"; | |
# create a new object | |
my $inotify = new Linux::Inotify2 or die "unable to create new inotify object: $!"; | |
# add watchers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojo::IOLoop; | |
use feature 'say'; | |
Mojo::IOLoop->timer(5 => sub { | |
say "It has been 5 seconds, it is now ".localtime; | |
} ); | |
say "It is now ".localtime; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Event Driven Programming | |
- no blocking | |
- no polling | |
- no sleeping | |
- events and callbacks | |
- inotify vs stat | |
- sleep vs timers | |
- web services |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Test::More qw/no_plan/; | |
use Test::Mojo; | |
use Mojolicious::Lite; | |
get '/u' => 'index'; | |
my $t = Test::Mojo->new(); | |
$t->get_ok( $t->ua->app_url->userinfo('secret:pass')->path('/u') |
OlderNewer