Skip to content

Instantly share code, notes, and snippets.

View Ovid's full-sized avatar

Ovid Ovid

View GitHub Profile
@Ovid
Ovid / perlclasstut.pod
Last active December 6, 2022 10:40
Corinna Class Tutorial
@Ovid
Ovid / SeKreT.pm
Created May 15, 2022 10:31
New test SQLite databases on the fly
# I needed to sure I was operating on pristine test databases
# every time my code called $test->schema (DBIx::Class and Test::Class::Moose).
# This handles that for me
package TestsFor::SeKreT {
use Test::Class::Moose;
use Less::Boilerplate; # gives me a sane version of Perl
use File::Copy qw(copy);
use File::Spec::Functions qw(catfile);
use SeKreT::Util::Data qw(
make_slug
@Ovid
Ovid / exception.md
Last active March 21, 2022 06:51
Exceptions in Perl?

Preface

This is something that likely cannot be made into an RFC for the Perl language at this time because implementation would be greatly simplified when the Corinna object model is in core. For example, a base class for what is discussed might look like the following:

# Exception is a poor name for warnings, so a better name is warranted
class Exception :version(v0.1.0) {
    # $message and $description might be from a messaging role
    field $message     :reader :param;
    field $description :reader :param { "" };
@Ovid
Ovid / dep-scanner.pl
Last active November 12, 2021 12:33
Sample of PPR-based dependency scanner
#!/usr/bin/env perl
# I decided it was time to learn PPR::X (Damian Conway's excellent regex-based Perl parser)
#
# This code is still heuristic in nature, but the challenge seemd fun.
#
# I thought it would be an interesting project to try to extract dependencies from
# Perl code. Thanks to `haj` giving me the clue needed to find a parsing error
use strict;
@Ovid
Ovid / Counter.pl
Created February 8, 2021 10:14
user-defined attributes in Cor?
class Counter {
# My::Cor::Attributes is using some hypothetical
# tool to extend Cor attributes. Because it's a
# `use` statement, it happens at compile time
use My::Cor::Attributes ':isa';
has $count :reader :new :isa(PositiveInt) = 0;
method inc () { $count++ }
method dec () { $count-- unless 0 == $count }
}
@Ovid
Ovid / grep.pm
Last active May 12, 2022 12:36
A small hack to add a 'sqitch grep ...' command that sorts things in the order of the sqitch plan
package App::Sqitch::Command::grep;
use 5.010;
use strict;
use warnings;
use utf8;
use App::Sqitch::X qw(hurl);
use Moo;
use App::Sqitch::Target;
use App::Sqitch::Types qw(Str Enum Target Bool);
@Ovid
Ovid / cor_attributes.md
Last active March 1, 2020 12:44
Cor attribute/slot declaration?

This is a rough draft of some thoughts I've had regarding Cor attributes declaration. Please leave your thoughts.

Part of the problem with the Cor object proposal for the Perl code is that we tended to use the semantics of has as declared in the Moose OO extension for Perl. Unfortunately, this function handles:

  • Data
@Ovid
Ovid / alter-table.pl
Created January 25, 2020 09:49
Script to make altering tables in SQLite easier
#!/usr/bin/env perl
# ALTER TABLE syntax in SQLite is very limited. This script follows the pattern
# outlined in https://www.sqlite.org/lang_altertable.html to make it easier to
# alter a table in SQLite
# this script is designed to use core Perl so that non-Perl users can use it
use 5.6.1; # minimum version for File::Temp
use strict;
use warnings;
@Ovid
Ovid / babylonian.pl
Last active December 9, 2019 12:34
Convert from Arabic to Babylonian numerals (only positive integers)
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
binmode STDOUT, ':utf8_strict';
my $num = shift;
if ( $num < 1 || $num != int($num) ) {
die "'$num' is not a positive integer";
}
@Ovid
Ovid / Boilerplate.pm
Last active August 11, 2020 01:49
use less boilerplate
package Less::Boilerplate;
use 5.26.0;
use strict;
use warnings;
use feature ();