in reply to Re^2: STDIN typeglob
in thread STDIN typeglob
Perhaps, your module should not fetch the data at all, but just accept the data as a scalar value. Both would also allow for easier testing.
That is exactly what I was thinking!
In the hope it clarifies Bod's question, I think the module in question is Business::Stripe::Webhook, whose version 1.0 constructor is:
sub new { my $class = shift; my %vars = @_; $vars{'error'} = ''; $vars{'reply'} = { 'status' => 'noaction', 'sent_to' => [ ], 'sent_to_all' => 'false', }; if (exists $ENV{'GATEWAY_INTERFACE'}) { read(STDIN, $vars{'payload'}, $ENV{'CONTENT_LENGTH'}); $vars{'webhook'} = decode_json($vars{'payload'}) if $vars{'pay +load'}; $vars{'error'} = 'No payload data' unless $vars{'webhook'}; } else { $vars{'error'} = 'Looks like this is not a web request!'; } return bless \%vars, $class; }
Though I'm definitely not a Web programmer, from an interface and TDD point of view, I pulled a face the instant I saw the constructor using an environment variable to decide whether to read from STDIN or not.
It seems clearer and easier to test if this module were to simply accept a payload property. That way, the module's tests can easily pass in all sorts of dodgy payloads to see how it handles bad input.
That is, instead of trying to do everything in one module, use several, smaller, more cohesive modules to get the job done.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: STDIN typeglob
by afoken (Chancellor) on Jun 12, 2023 at 19:53 UTC | |
by Bod (Parson) on Jun 13, 2023 at 20:42 UTC | |
Re^4: STDIN typeglob
by Bod (Parson) on Jun 13, 2023 at 20:58 UTC | |
by eyepopslikeamosquito (Archbishop) on Jun 14, 2023 at 00:24 UTC | |
by Bod (Parson) on Jun 18, 2023 at 17:13 UTC |