diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-05-19 06:34:01 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-06-28 22:41:55 +0200 |
commit | 10918f3336863623020a6d73e63a0f0a5eebb306 (patch) | |
tree | a496e36a1f149e193a4ceed41531034a6b2ae888 /Bugzilla/Quantum/Legacy.pm | |
parent | 215f1021948b63cad29094e7847b52c256ec9974 (diff) | |
download | bugzilla-10918f3336863623020a6d73e63a0f0a5eebb306.tar.gz bugzilla-10918f3336863623020a6d73e63a0f0a5eebb306.tar.xz |
mojo all the things
Diffstat (limited to 'Bugzilla/Quantum/Legacy.pm')
-rw-r--r-- | Bugzilla/Quantum/Legacy.pm | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/Bugzilla/Quantum/Legacy.pm b/Bugzilla/Quantum/Legacy.pm index 73e877af3..d093d76a0 100644 --- a/Bugzilla/Quantum/Legacy.pm +++ b/Bugzilla/Quantum/Legacy.pm @@ -7,41 +7,52 @@ package Bugzilla::Quantum::Legacy; use Mojo::Base 'Mojolicious::Controller'; +use CGI::Compile; use File::Spec::Functions qw(catfile); use Bugzilla::Constants qw(bz_locations); use Taint::Util qw(untaint); use Sub::Name qw(subname); -use autodie; +use File::Slurper qw(read_text); +use Sub::Quote 2.005000; +use Try::Tiny; -_load_cgi(index_cgi => 'index.cgi'); -_load_cgi(show_bug => 'show_bug.cgi'); +my %CGIS; +my %SKIP = ( 'xmlrpc.cgi' => 1, 'jsonrpc.cgi' => 1, 'rest.cgi' => 1); -sub _load_cgi { - my ($name, $file) = @_; - my $content; - { - local $/ = undef; - open my $fh, '<', catfile(bz_locations->{cgi_path}, $file); - $content = <$fh>; - untaint($content); - close $fh; +_load_all(); + +sub expose_routes { + my ($class, $r) = @_; + foreach my $cgi (keys %CGIS) { + $r->any("/$cgi")->to("Legacy#$CGIS{$cgi}"); } - my $pkg = __PACKAGE__ . '::' . $name; - my @lines = ( - qq{package $pkg;}, - qq{#line 1 "$file"}, - "sub { my (\$self) = \@_; $content };" - ); - my $code = join "\n", @lines; - my $sub = _eval($code); - { - no strict 'refs'; ## no critic (strict) - *{ $name } = subname($name, $sub); +} + +sub _load_all { + foreach my $script (glob '*.cgi') { + next if $SKIP{$script}; + my $name = _load_cgi($script); + $CGIS{ $script } = $name; } } -sub _eval { ## no critic (unpack) - return eval $_[0]; ## no critic (eval) +sub _load_cgi { + my ($file) = @_; + my $name = $file; + $name =~ s/\./_/g; + $name =~ s/\W+/_/g; + my $content = read_text(catfile(bz_locations->{cgi_path}, $file)); + untaint($content); + $content = 'my ($self) = @_; ' . $content; + my %options = ( + package => __PACKAGE__ . "::$name", + file => $file, + line => 1, + no_defer => 1, + ); + quote_sub $name, $content, {}, \%options; + return $name; } -1;
\ No newline at end of file + +1; |