Skip to content

Instantly share code, notes, and snippets.

@preaction
preaction / test_moo.pl
Created December 14, 2014 02:59
Attribute value after clearer is called differs between lazy and non-lazy
{
package FooMoo;
use Moo;
has foo => (
is => 'rw',
default => sub { 'foo' },
clearer => 1,
);
@preaction
preaction / gist:afa3588b56971cc86776
Last active August 29, 2015 14:11
Read from /dev/urandom
use strict;
use warnings;
use Mojo::IOLoop::Stream;
my $stream = Mojo::IOLoop::Stream->new(IO::File->new("</dev/urandom"));
$stream->on(read => sub {
my ($stream, $bytes) = @_;
print STDERR "Read from stream\n";
});
$stream->on(error=>sub {
@preaction
preaction / mojoapp.t
Created November 29, 2014 18:31
Redirect route not working
use Test::Mojo;
{
package Statocles::Command::_MOJOAPP;
# Currently, as of Mojolicious 5.12, loading the Mojolicious module here
# will load the Mojolicious::Commands module, which calls GetOptions, which
# will remove -h, --help, -m, and -s from @ARGV. We fix this by copying
# @ARGV in bin/statocles before we call Statocles::Command.
@preaction
preaction / mojoapp.t
Last active August 29, 2015 14:10
Server only works once?
use Test::More;
use Mojo::Base;
use Mojo::IOLoop;
use Mojo::IOLoop::Delay;
use Mojo::UserAgent;
use Mojo::IOLoop;
{
package Statocles::Command::_MOJOAPP;
C also enables all features available in the requested version as defined by the C pragma, disabling any features not in the requested version's feature bundle. See L. Similarly, if the specified Perl version is greater than or equal to 5.12.0, strictness is enabled lexically as with C. Any explicit use of C or C overrides C, even if it comes before it. The F and F files are not used for C.
» perl -e'use strict "vars"; BEGIN { printf "\%8d -> %60s", $^H, unpack( "b*", $^H ) }'
1408 -> 10001100001011000000110000011100
» perl -e'use strict "subs"; BEGIN { printf "\%8d -> %60s", $^H, unpack( "b*", $^H ) }'
832 -> 000111001100110001001100
» perl -e'use strict "refs"; BEGIN { printf "\%8d -> %60s", $^H, unpack( "b*", $^H ) }'
290 -> 010011001001110000001100
» perl -e'use strict; BEGIN { printf "\%8d -> %60s", $^H, unpack( "b*", $^H ) }'
2018 -> 01001100000011001000110000011100
» perl -e'use strict "refs", "vars", "subs"; BEGIN { printf "\%8d -> %60s", $^H, unpack( "b*", $^H ) }'
2018 -> 01001100000011001000110000011100
use strict;
use feature qw( :5.16 );
use DateTime;
my $now = DateTime->now( time_zone => 'America/Chicago' );
my $lon = DateTime->today( time_zone => 'Europe/London' );
$lon->set_hour( 6 );
$lon->set_minute( 22 );
while ( $lon < $now ) {
@preaction
preaction / test-ae-timer.pl
Created June 9, 2014 20:07
Test that AnyEvent timer events happen when advertised
use Test::MockTime qw( set_absolute_time );
# Use the Pure-Perl loop so we can do janky things with time
use AnyEvent::Loop;
# set_absolute_time will update what time AnyEvent thinks it is
# Then you can run AnyEvent::Loop::one_event to run the event loop
# until something happens.
#
# AnyEvent::Loop::one_event will call _update_clock to get the current time. If
---
title: A Test Post
author: preaction
content: |
# Markdown content goes here.
This is a new post using the brand-new command system.
Don't forget to maintain the indentation.
@preaction
preaction / MyApp.pm
Created May 7, 2014 22:36
Test an app that uses Mojo::UserAgent as a proxy
package MyApp;
use Mojo::Base 'Mojolicious';
=attr rest_url
The URL to the REST API
=cut