Skip to content

Instantly share code, notes, and snippets.

@wesQ3
Created December 9, 2025 19:17
Show Gist options
  • Select an option

  • Save wesQ3/6b4f1652b95894b014a9dd21a32d23fa to your computer and use it in GitHub Desktop.

Select an option

Save wesQ3/6b4f1652b95894b014a9dd21a32d23fa to your computer and use it in GitHub Desktop.
DBIC::DH and feature module_true
#! /usr/bin/env perl
use strict; use warnings;
use feature 'say';
use lib '.';
use Carp 'croak';
use Data::Dumper::Concise;
use Digest::MD5 'md5_hex';
use Try::Tiny;
# Adapted from lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm
sub _load_sandbox {
my $_file = shift;
$_file = "$_file";
# my $_package = _generate_script_package_name($_file);
my $_package = 'A::Package::'.md5_hex("$_file");
my $fn = eval sprintf <<'END_EVAL', $_package;
package %s;
{
our $app;
$app ||= require $_file;
if ( !$app && ( my $error = $@ || $! )) { die $error; }
$app;
}
END_EVAL
croak $@ if $@;
croak "$_file should define an anonymous sub that takes a schema but it didn't!"
unless ref $fn && ref $fn eq 'CODE';
return $fn;
}
sub _run_perl {
my ($self, $filename, $versions) = @_;
say "Running Perl from $filename";
my $fn = _load_sandbox($filename);
say "Running Perl ". Dumper($fn);
try {
# $fn->($self->schema, $versions)
$fn->()
} catch {
die "failed to run Perl in $filename: $_"
};
say "\n";
}
_run_perl(0, 'no_module_true.pl');
_run_perl(0, 'use_module_true.pl');
#!/usr/bin/env perl
use v5.40; use warnings;
no feature 'module_true';
sub {
say 'module_true disabled';
};
#!/usr/bin/env perl
use v5.40; use warnings;
sub {
say 'using module_true';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment