Created
December 9, 2025 19:17
-
-
Save wesQ3/6b4f1652b95894b014a9dd21a32d23fa to your computer and use it in GitHub Desktop.
DBIC::DH and feature module_true
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use v5.40; use warnings; | |
| no feature 'module_true'; | |
| sub { | |
| say 'module_true disabled'; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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