Skip to content

Instantly share code, notes, and snippets.

View akarelas-pt's full-sized avatar

Alexander Karelas akarelas-pt

View GitHub Profile
@akarelas-pt
akarelas-pt / crash_3.pl
Last active June 4, 2019 20:05
this always crashes
#!/opt/perl-5.28.0/bin/perl
use v5.28;
use warnings;
use FindBin '$RealBin', '$RealScript';
use lib "$RealBin/local/lib/perl5", "$RealBin/lib";
use DateTime::Format::Strptime;
use Storable 'store', 'retrieve';
use Data::Dumper;
@akarelas-pt
akarelas-pt / wantarray.pl
Created March 12, 2019 16:15
wantarray in try
#!/usr/bin/perl
use v5.26;
use warnings;
use Syntax::Keyword::Try;
use Data::Dumper;
sub goo {
try {
@akarelas-pt
akarelas-pt / work-notwork-2.pl
Last active June 29, 2018 14:43
Doesn't work - Works
package My::Schema::Result;
use v5.26;
use warnings;
use parent 'DBIx::Class::Core';
use Sub::Util 'set_subname';
__PACKAGE__->load_components('Helper::Row::RelationshipDWIM');
@akarelas-pt
akarelas-pt / work-nowork.pl
Created June 20, 2018 12:04
Why does one work and the other doesn't?
package My::Schema::Result;
use v5.24;
use warnings;
use parent 'DBIx::Class::Core';
sub default_result_namespace { 'My::Schema::Result' }
use Sub::Util 'set_subname';
@akarelas-pt
akarelas-pt / My_Schema_Result.pm
Created June 19, 2018 13:11
DBIx::Class: enable cascade_delete, only if user has explicitly enabled it
use Sub::Util 'set_subname';
foreach my $method (qw/ has_many belongs_to might_have has_one /) {
no strict 'refs';
*{ $method } = set_subname __PACKAGE__."::$method" => sub {
my $class = shift;
my $opts = $_[3] || {};
foreach my $action (qw/ copy delete update /) {
$opts->{"cascade_$action"} //= 0;
}
# In your base Result class ( ...::Schema::BaseResult )
sub add_relationship {
my $self = shift;
my $opts = $_[3] || {};
# shut off all DBIC/perl-side cascading logic
$opts->{cascade_delete} = 0;
$opts->{cascade_update} = 0;
$opts->{cascade_copy} = 0;
@akarelas-pt
akarelas-pt / .perltidyrc
Created January 25, 2018 07:36
Place this in your homedirectory
-ci=2
-l=150
-bt=2
-pt=2
-sbt=2
-noll
@akarelas-pt
akarelas-pt / myapp.pl
Created December 14, 2017 11:05
Shows error on browser when uploading file of size 100MB
#!/usr/bin/env perl
use Mojolicious::Lite;
app->max_request_size(10 * 1024);
get '/' => sub {
my $c = shift;
$c->render(template => 'index');
};
@akarelas-pt
akarelas-pt / jv.pl
Created November 24, 2017 14:02
no rules returns error
#!/usr/bin/env perl
use v5.16;
use warnings;
use lib 'local/lib/perl5';
use JSON::Validator;
use Data::Dumper;
my $v = JSON::Validator->new;
@akarelas-pt
akarelas-pt / dropped.pl
Created November 24, 2017 10:08
repeated dropped connection causes DBIC to fail
#!/usr/bin/env perl
use FindBin '$Bin';
use lib "$Bin/local/lib/perl5", "$Bin/lib";
use v5.16;
use warnings;
use My::Schema;
use Data::Dumper;