plack / Plack

PSGI toolkit and server adapters
http://plackperl.org/
Other
486 stars 214 forks source link

show warnings if enable/enable_if is called in non-void context #669

Open karupanerura opened 3 years ago

karupanerura commented 3 years ago

Example: the following code looks like the correct code, but in fact, it mistakenly uses a comma as a semicolon.

builder {
     enable 'ReverseProxy';
     enable 'Session::Cookie',
         session_key => 'session',
         expires     => 3600,
         secret      => 'mysecret', # incorrect: should be terminated by ;
     enable 'Static',
         path => qr!^/assets/!,
         root => './assets/';
     $app;
};

It expect to see errors and warnings, but in fact this code has the correct syntax for Perl, so no errors or warnings will be shown. In this code, the Middleware will be applied in the following order: ReverseProxy -> Static -> Session::Cookie (not ReverseProxy -> Session::Cookie -> Static)

The following is the result of B::Deparse on this code:

&builder(sub {
    enable('ReverseProxy');
    enable('Session::Cookie', 'session_key', 'session', 'expires', 3600, 'secret', 'mysecret', enable('Static', 'path', qr"^/assets/", 'root', './assets/'));
    $app;
})

To warning such a mistake, how about displaying warnings like this patch when enable/enable_if is called on void context? I think enable/enable_if should be called in a void context in general.

related blog entry (Japanese): https://memo.sugyan.com/entry/2021/08/23/003752