Re: [Mojolicious] MUA::Transactor::add_generator

2019-03-12 Thread Dan Book
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  wrote:

> I built a generator for AWS Signature4 requests
> .
> 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
> 
> 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.
> 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.
>

-- 
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.


Re: [Mojolicious] MUA::Transactor::add_generator

2019-03-12 Thread Stefan Adams
Thanks, Dan!  I updated the gist
 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  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  wrote:
>
>> I built a generator for AWS Signature4 requests
>> .
>> 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
>> 
>> 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.
>> 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.
>>
> --
> 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.
>

-- 
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.


Re: [Mojolicious] MUA::Transactor::add_generator

2019-03-12 Thread Илья Рассадин

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 
 
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 > 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 mailto:s1037...@gmail.com>> wrote:

I built a generator for AWS Signature4 requests
. 
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


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
.
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.

-- 
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.

--
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.


--
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.


Re: [Mojolicious] MUA::Transactor::add_generator

2019-03-13 Thread Stefan Adams
Thanks for the great suggestion!  I thought about the Role method, but
couldn't understand how to make that work nice.  I got onto IRC and was
given the advice that I believe you inferred to use Role::Tiny 'around',
and that solves it very well!

Updated gist
 using
around

.

Thanks for the help, everyone!

On Wed, Mar 13, 2019 at 1:13 AM Илья Рассадин  wrote:

> 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
>  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  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  wrote:
>>
>>> I built a generator for AWS Signature4 requests
>>> .
>>> 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
>>> 
>>> 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.
>>> 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.
>>>
>> --
>> 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.
>>
> --
> 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.
>
> --
> 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.
>

-- 
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.