Skip to content

Instantly share code, notes, and snippets.

View tobyink's full-sized avatar
🦈
hi

Toby Inkster tobyink

🦈
hi
View GitHub Profile
@tobyink
tobyink / XSConstructor.xs
Created June 19, 2018 17:05
XSConstructor.xs
#include "xshelper.h"
#define IsObject(sv) (SvROK(sv) && SvOBJECT(SvRV(sv)))
#define IsArrayRef(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVAV)
#define IsHashRef(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVHV)
#define IsCodeRef(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVCV)
#define XSCON_xc_stash(a) ( (HV*)XSCON_av_at((a), XSCON_XC_STASH) )
static HV*
Program received signal SIGSEGV, Segmentation fault.
0x0000555555616f00 in Perl_hv_common ()
(gdb) bt
#0 0x0000555555616f00 in Perl_hv_common ()
#1 0x0000555555618144 in Perl_hv_common_key_len ()
#2 0x00007ffff69060a9 in XS_Class__XSConstructor_new ()
from /home/tai/src/p5/p5-class-xsconstructor/Class-XSConstructor-0.001/blib/arch/auto/Class/XSConstructor/XSConstructor.so
#3 0x0000555555623e09 in Perl_pp_entersub ()
#4 0x000055555561bf33 in Perl_runops_standard ()
#5 0x00005555555a7b74 in perl_run ()
@tobyink
tobyink / example.pl
Last active June 24, 2017 21:35
Demonstration of Template::Compile
use Types::Standard -types;
use Template::Compiled;
my $template = Template::Compiled->new(
signature => [
name => Str,
age => Int->plus_coercions(Num, sub { int $_ } ),
],
template => '<p>Hi <?= $name ?>. You are <?= $age ?> years old.</p>',
escape => 'html',
use strict;
use warnings;
{
package Widget;
use Moose;
has identifier => (
is => 'ro',
isa => 'Int',
required => !!1,
use strict;
use warnings;
use Data::Dumper;
{
package My::Example;
use Moose;
use Scalar::Util qw(weaken);
use Hash::Util::FieldHash::Compat qw(fieldhash);
use v5.16;
package Person {
use Moo;
use MooseX::MungeHas { has => [], lazy => [qw/is_lazy/] };
lazy name => sub { "Bob" };
}
say Person->new->name;
package My::Person;
use Moo;
use MooX::Press;
has name => RO REQUIRED Str, documentation => 'Full name';
has favourite_number => RO DEFAULT { 7 } Int;
1;
use strict;
use warnings;
use Benchmark qw( cmpthese );
{
package Example::Base;
use Moo;
use MooX::ValidateSubs;
use Types::Standard qw/Str ArrayRef HashRef/;
use strict;
use warnings;
use Benchmark qw( cmpthese );
{
package Example::Base;
use Moo;
use MooX::ValidateSubs;
use Types::Standard qw/Str ArrayRef HashRef/;
# The old way
use v5.10;
use strict;
use warnings;
use Test::More;
use Type::Tiny;
use Types::Standard qw( Int );