For Programmers: Free Programming Magazines  


Home > Archive > PERL POE > November 2005 > using context data in PoCo Client DNS









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author using context data in PoCo Client DNS
Rohan R. Almeida

2005-11-10, 7:59 am

Hi,

How do I pass along some context data to the resolve event?

I know how to do it this way:

<code>

my $response =3D $named->resolve(
event =3D> "response",
host =3D> "localhost",
context =3D> $my_data,
);

</code>

But i'm not calling the "resolve" method, and instead posting a resolve eve=
nt.

Like this:

<code>

$kernel->post(
'resolver', # Post to resolver component
'resolve', # Call this event
'response', # Call this event of our session on answer
$host, # The domain to resolve
'A', 'IN', # The record type and class to find
$my_data, # Is this right?
);

</code>

Additionally, how do I get this data in the 'response' event?

The docs don't have any examples of using the 'context' data in the second =
form.

Thanks!

--
Rohan
http://rohan.almeida.in
Mathieu Longtin

2005-11-10, 7:59 am

Speaking of which, I have been wondering why POE is
implemented with a whole bunch of names instead of
references. Any reason for that design decision?

Example:

$kernel->post('resolver', 'resolve',
'response',
$host, 'A', 'IN');

Wouldn't it have been cleaner and less error prone to have
something like this:

$resolver->resolve(&response_callback, $host, 'A', 'IN');

Notice that this way, the compiler can catch most
misspelling.


-Mathieu




__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
Kidney Bingos

2005-11-10, 7:07 pm

On Thu, Nov 10, 2005 at 04:20:56PM +0530, Rohan R. Almeida wrote:
> How do I pass along some context data to the resolve event?
>
> I know how to do it this way:
>
> <code>
>
> my $response = $named->resolve(
> event => "response",
> host => "localhost",
> context => $my_data,
> );
>
> </code>
>
> But i'm not calling the "resolve" method, and instead posting a resolve event.
>
> Like this:
>
> <code>
>
> $kernel->post(
> 'resolver', # Post to resolver component
> 'resolve', # Call this event
> 'response', # Call this event of our session on answer
> $host, # The domain to resolve
> 'A', 'IN', # The record type and class to find
> $my_data, # Is this right?
> );
>
> </code>
>
> Additionally, how do I get this data in the 'response' event?
>
> The docs don't have any examples of using the 'context' data in the second form.
>


Hi,

According to the docs the second form is deprecated and scheduled for future removal, hence no mentions in the documentation.

So, your best bet is the first form and the docs fully ...erm ... document the use of 'context' using the new API.

Regards,

--
Chris Williams
aka BinGOs
PGP ID 0x4658671F
http://www.gumbynet.org.uk
==========================

Rohan R. Almeida

2005-11-10, 7:07 pm

On 11/10/05, Rohan R. Almeida <arcofdescent@gmail.com> wrote:
> <code>
>
> $kernel->post(
> 'resolver', # Post to resolver component
> 'resolve', # Call this event
> 'response', # Call this event of our session on answe=

r
> $host, # The domain to resolve
> 'A', 'IN', # The record type and class to find
> $my_data, # Is this right?
> );
>
> </code>
>
> Additionally, how do I get this data in the 'response' event?
>


I went through the docs for PoCo Client::Ping and stole from there.

The following works:

<code>

$kernel->post(
'resolver', # Post to resolver component
'resolve', # Call this event
['response', $my_data], # Call this event of our
session on answer
$host, # The domain to resolve
'A', 'IN', # The record type and class to find
$my_data, # Is this right?
);

</code>

The contextual data should be passed in an array ref.

Thanks,
Rohan
http://rohan.almeida.in
Rocco Caputo

2005-11-10, 7:07 pm

On Nov 10, 2005, at 08:51, Mathieu Longtin wrote:

> Speaking of which, I have been wondering why POE is
> implemented with a whole bunch of names instead of
> references. Any reason for that design decision?
>
> Example:
>
> $kernel->post('resolver', 'resolve',
> 'response',
> $host, 'A', 'IN');
>
> Wouldn't it have been cleaner and less error prone to have
> something like this:
>
> $resolver->resolve(&response_callback, $host, 'A', 'IN');
>
> Notice that this way, the compiler can catch most
> misspelling.


POE has grown organically, building up from simple ideas with simple
extensions. Not all of its growth is perfect.

There's a new project, POE::Stage on the CPAN. I hope it will
formalize some of the stronger component design patterns that have
arisen over the years. It includes a DNS resolver, but it's not as
featureful as POE::Component::Client::DNS.

By the way, your cleaner example contains an error. :)

--
Rocco Caputo - http://poe.perl.org/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com