Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/perl
use lib 'lib';
use Test::More;
use Test::Fatal;
{
package R1;
use Role::Tiny;
$ perl -E 'package R; use Role::Tiny; sub foo { "R1 foo" }; package R2; use Role::Tiny; sub foo { "R2 foo" }; package X; use Role::Tiny::With; sub new { bless {} }; my $x = X->new; Role::Tiny->apply_roles_to_object($x, "R", "R2"); say $x->foo;'
R2 foo
@berekuk
berekuk / blah.txt
Created May 24, 2012 22:25
daemon-control-issues
Sorry, I'm too lazy to file each one of these bugs separately, and I really think you should adopt `Ubic::Daemon` instead.
You should close all filehandles; simple test: `ssh localhost '/etc/init.d/foo start'` will hang otherwise.
`exit 1` if service is already running is not LSB compatible. Also, not supporting force-reload and try-restart.
Not saving pidfile atomically means that your code will break if you recreated the pidfile but failed because of random kill (oom, for example), or after reboot. Simple test: `echo >file.pid` will break your service forever.
If you don't keep any additional guid in your pidfile, this means that at the time you call `/etc/init.d/foo stop`, you can kill the wrong process.
package X;
use Moose;
with 'Yandex::Runnable'; # yeah, I didn't got along well with MooseX::Runnable, don't remember why
sub main {
...
}
__PACKAGE__->run_script; # magic!
@berekuk
berekuk / output.txt
Created May 17, 2012 19:27
require fails when called from exception()
$ ./test.t
exception script.pl did not return a true value at ./test.t line 9.
$ perl --version
This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi
* * * * * . /Users/mmcleric/etc/bash/local && ubic-watchdog ubic.watchdog >>/dev/null 2>>/dev/null
@berekuk
berekuk / app.pl
Created May 1, 2012 16:08
trivial ubic-web
#!/usr/bin/perl
use Dancer;
use Ubic;
my @commands = qw( start stop status restart try-restart reload force-reload);
post '/:service/:command' => sub {
my $service = param('service');
my $command = param('command');
package Wrap;
...
sub lag {
die unless $self->{wrapped}->DOES('Stream::Role::Lag');
return $self->{wrapped}->lag;
}
sub DOES {
return $self->{wrapped}->DOES(@_);
package Stream::Out;
# doesn't return anything
sub write_chunk {
}
package Stream::Filter;
# returns rewritten chunk
@berekuk
berekuk / mx_does_example.pl
Created February 28, 2012 13:23
MooseX::DOES module proposal
package R;
use Moose::Role;
# My::Role::Foo is just a string which affects DOES() behaviour, nothing else
# plan for implementation:
# 1) add MX::Does::Role role to R which wraps DOES with around DOES => sub { ... }
# 2) call $role_metaclass->add_attribute('additional_DOES', ...)
# 3) iterate over role metaclasses in DOES wrapper in MX::Does::Role
use MooseX::DOES qw/ My::Role::Foo My::Role::Bar /;