in reply to Re^3: STDIN typeglob
in thread STDIN typeglob
sub new { my $class = shift; my %vars = @_; $vars{'error'} = ''; $vars{'reply'} = { 'status' => 'noaction', 'sent_to' => [ ], 'sent_to_all' => 'false', }; if (!exists{'payload'}) { # Obtaining payload from STDIN only # exists for backward compatability # This option is deprecated and will # be removed in a future version if (exists $ENV{'GATEWAY_INTERFACE'}) { read(STDIN, $vars{'payload'}, $ENV{'CONTENT_LENGTH'}); $vars{'webhook'} = decode_json($vars{'payload'}) if $vars{ +'payload'}; $vars{'error'} = 'No payload data' unless $vars{'webhook +'}; } else { $vars{'error'} = 'Looks like this is not a web request!' +; } } return bless \%vars, $class; }
It seems clearer and easier to test if this module were to simply accept a payload property
Is that a better constructor?
The production version of the module has been released so I don't want to break that. So the new method now accepts a payload property. If that is missing and it is running on a webserver with the right environment, it falls back to the previous behaviour.
A couple of versions down the line I will remove the fallback code and set an error condition if payload is not a valid JSON scalar.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: STDIN typeglob
by eyepopslikeamosquito (Archbishop) on Jun 14, 2023 at 00:24 UTC | |
by Bod (Parson) on Jun 18, 2023 at 17:13 UTC |