Hi!

name "add_generator" leads me to the idea, that there can be more than one aws sign generators. apply_generator or set_generator makes it clear, that there can be only one.

And by the way, why don't you encapsulate generator logic inside role AWSSign role?

So, code could be something like

my $ua = Mojo::UserAgent->with_roles('+AWSSign')->new(max_redirects => 5);

my $tx = $ua->build_tx(...);

On 13/03/2019 01:18, Stefan Adams wrote:
Thanks, Dan!  I updated the gist <https://gist.github.com/s1037989/479087c752d7461d3499c12971636678> with your recommendation, and my new synopsis is this:

    Mojo::AWS::Signature4->add_generator($ua => 'sign');
    my $tx = $ua->build_tx(GET => '...' => sign => {service => 'ec2'});


Does add_generator feel like the right method name for this?  Maybe apply_generator, instead?

On Tue, Mar 12, 2019 at 4:45 PM Dan Book <gri...@gmail.com <mailto:gri...@gmail.com>> wrote:

    That seems like the appropriate mechanism to me. If you want to
    provide a convenience method, I would instead provide one that
    takes the $ua object and an optional generator name, and calls
    ->add_generator itself. It would also be subclassable since it
    could call a method on $self instead of __PACKAGE__.
    -Dan

    On Tue, Mar 12, 2019 at 5:22 PM Stefan Adams <s1037...@gmail.com
    <mailto:s1037...@gmail.com>> wrote:

        I built a generator for AWS Signature4 requests
        <https://gist.github.com/s1037989/479087c752d7461d3499c12971636678>. 
        This generator calculates a signed Authorization header for
        the request.  Is this a good use of the Transactor generator
        feature?

        As you can see from L13
        
<https://gist.github.com/s1037989/479087c752d7461d3499c12971636678#file-ec2-t-L13>
        of the supplied test, I make my generator available this way:

            $ua->transactor->add_generator(Mojo::AWS::Signature4::generator);


        Is this the best mechanism available to share this generator,
        or is there a recommended standard convention?  When I go to
        document it for publishing, is that what I should have in the
        synopsis section? It almost feels like there should be a
        plugin mechanism for Mojo::UserAgent.

        Thanks for any advice and comments you have!

        Stefan
-- You received this message because you are subscribed to the
        Google Groups "Mojolicious" group.
        To unsubscribe from this group and stop receiving emails from
        it, send an email to mojolicious+unsubscr...@googlegroups.com
        <mailto:mojolicious+unsubscr...@googlegroups.com>.
        To post to this group, send email to
        mojolicious@googlegroups.com
        <mailto:mojolicious@googlegroups.com>.
        Visit this group at https://groups.google.com/group/mojolicious.
        For more options, visit https://groups.google.com/d/optout.

-- You received this message because you are subscribed to the Google
    Groups "Mojolicious" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to mojolicious+unsubscr...@googlegroups.com
    <mailto:mojolicious+unsubscr...@googlegroups.com>.
    To post to this group, send email to mojolicious@googlegroups.com
    <mailto:mojolicious@googlegroups.com>.
    Visit this group at https://groups.google.com/group/mojolicious.
    For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com <mailto:mojolicious+unsubscr...@googlegroups.com>. To post to this group, send email to mojolicious@googlegroups.com <mailto:mojolicious@googlegroups.com>.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to