出于测试目的,我想创建一个包装脚本,它可以在不更改原始脚本的情况下向现有脚本添加功能。我的问题是,这在 perl 中是否可行,我该怎么做?
包装脚本将执行以下操作:
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Aspect;
run syntax checking on config files;
run unittesting stuff;
call production script;
生产脚本将保持不变并且完全独立:
#!/usr/bin/perl
use strict;
use warnings;
bunch of production code here;
当然,我希望诊断和方面编织能够处理生产代码。我已经尝试了一些简单的事情,但它们没有用,代码甚至没有运行。
eval { require "production.pl" };
do 'production.pl';
require 'production.pl';