Skip to content

Instantly share code, notes, and snippets.

@pavelsr
Created November 2, 2018 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavelsr/18d3004a9ce4fff916aba737ce5583de to your computer and use it in GitHub Desktop.
Save pavelsr/18d3004a9ce4fff916aba737ce5583de to your computer and use it in GitHub Desktop.
Some magic here
#!/bin/bash
# docker exec -it 220v_apache_1 cpanm DBI::Log
# git diff to check changes
sed -i '15iuse main_config;' htdocs/cgi-bin/a0/pbh-preprocessor.pl
sed -i '16iuse DBI::Log file => "debug.log";' htdocs/cgi-bin/a0/pbh-preprocessor.pl
sed -i '21iuse Middleware::Stacktrace;' framework/lib/Perl5/DDV/ControllerRunner.pm
cat >framework/lib/Perl5/Middleware/Stacktrace.pm <<'EOL'
package Middleware::Stacktrace;
use strict;
use warnings FATAL => 'all';
use parent qw/Uber::Middleware/;
use main_config;
use Log::Any qw($log);
use Log::Any::Adapter;
use File::Spec;
use List::MoreUtils qw(uniq);
no warnings 'redefine';
use Text::Tmpl2;
use DTL::Fast;
use Uber::Controller;
$ModPerl::PBHRegistry::DEBUG = 0;
my $live = 1;
my $timeout = 1;
my $dhtml_print = 1;
my $log_level = 'notice';
my @pbh_templates = ();
my @dtl_templates = ();
Log::Any::Adapter->set( 'Fille', file => 'debug.log', log_level => 'notice' );
sub print_log {
my $msg = shift;
$log->$log_level($msg);
}
$SIG{USR1} = sub {
@pbh_templates = uniq @pbh_templates;
@dtl_templates = uniq @dtl_templates;
if ( !$live ) {
print_log("--- Rendered THTML templates --- ");
print_log($_) for (@pbh_templates);
print_log("--- Rendered DTL templates --- ");
print_log($_) for (@dtl_templates);
}
};
my $ppid = $$;
if ( fork() == 0 ) {
sleep $timeout;
kill 'USR1', $ppid;
exit;
}
if ($main_config::DEBUG) {
my $z = \&Text::Tmpl2::render;
*Text::Tmpl2::render = sub {
my $pbh_tpl_rel_path = File::Spec->abs2rel( $_[0]->{filename}, '/var/www/ccxx/' );
push( @pbh_templates, $pbh_tpl_rel_path ) if !$live;
print_log( "Rendering template " . $pbh_tpl_rel_path ) if $live; # on render finish
goto &$z;
};
my $gt = \&DTL::Fast::get_template;
*DTL::Fast::get_template = sub {
print_log( "Rendering template " . $_[0] ) if ( $live && $dhtml_print );
push( @dtl_templates, $_[0] ) if !$live;
goto &$gt;
};
my $pr = \&Uber::Controller::create_page_response;
*Uber::Controller::create_page_response = sub {
print_log( "Routing to controller " . ref( $_[0] ) );
goto &$pr;
};
}
sub process_request {
my ( $self, $request ) = @_;
return $request;
}
1;
EOL
tail -f htdocs/cgi-bin/a0/debug.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment