in reply to [RFC] Module code and POD for CPAN

$attrs{'error'} = 'cancel-url and success-url cannot be de +rived from the environment and need to be provided' unless ($attrs{'c +ancel-url'} and $attrs{'success-url'}); $attrs{'error'} = 'Public API key provided is not a valid key' if +$attrs{'api-public'} and $attrs{'api-public'} !~ /^pk_/; $attrs{'error'} = 'Secret API key provided is not a valid key' unl +ess $attrs{'api-secret'} =~ /^sk_/; $attrs{'error'} = 'Secret API key provided as Public key' if $attr +s{'api-public'} and $attrs{'api-public'} =~ /^sk_/; $attrs{'error'} = 'Public API key provided as Secret key' if $attr +s{'api-secret'} =~ /^pk_/; $attrs{'error'} = 'Secret API key is too short' unless length $att +rs{'api-secret'} > 100; $attrs{'error'} = 'Secret API key is missing' unless $attrs{'api-s +ecret'}; return bless \%attrs, $class;

If you must use this style for signaling an error then perhaps you should document that gettting an object back (as opposed to undef) is not a guarantee that object construction succeeded but it should check for the success() my $obj = Bod::Stripe->new(...); die $obj->error() unless $obj->success(); (I have run through the POD diagonally and I think I did not see any mention).

bw, bliako

Replies are listed 'Best First'.
Re^2: [RFC] Module code and POD for CPAN
by Bod (Parson) on Apr 14, 2021 at 14:37 UTC
    If you must use this style for signaling an error then perhaps you should document that gettting an object back (as opposed to undef) is not a guarantee that object construction succeeded

    Good point thanks - I shall add that to the documentation.

    Returning an object came from advice given by GrandFather in Re: [RFC] Review of module code and POD
    "Consider having new return an instance of Bod::CRM with its error field set..."