Skip to content

Instantly share code, notes, and snippets.

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 ) {
» 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
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.
@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;
@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 / 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 / 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,
);
use v5.20;
use Class::Anonymous;
my %hash = (
foo => 'bar',
baz => 'fuzz',
);
@preaction
preaction / gist:a624521088c4b916bd84
Last active August 29, 2015 14:13
Simple readonly hash object
use strict;
use warnings;
use feature qw( say );
package Hash::Object;
sub new {
my ( $class, %self ) = @_;
return bless { %self }, $class;
}
@preaction
preaction / pythonic_packages.pl
Created January 16, 2015 05:22
Pythonic packages/classes
package My::Pythonic::Package {
use My::Pythonic qw( Base );
class MyClass extends Base {
}
}
# Now in package main again
use My::Pythonic::Package qw( MyClass );
my $obj = MyClass->new;