flamey has asked for the wisdom of the Perl Monks concerning the following question:

my $reportLink = WWW::Mechanize::Link->new( { url => 'http://www.website.com/report/runreport/30', attr => ([ 'fields[xxx.name]' => 'a name', 'fields[xxx.version]' => '5.34' ]) } ); $mech->put($reportLink);
does not work (the returned page is as if fields/params are wrong). however, w/ URI object I get my report:
my $reportLink = URI->new('http://www.website.com/report/runreport/30 +'); $reportLink->query_form([ 'fields[xxx.name]' => 'a name', 'fields[xxx.version]' => '5.34' ]); $mech->put($reportLink);
this is probably something silly i'm as a noob doing wrong, where's a mistake? TIA. P.S. it's weird, but I can't find any examples of people using WWW::Mechanize::Link :-/

Replies are listed 'Best First'.
Re: WWW::Mechanize::Link - how to?
by Corion (Patriarch) on Feb 16, 2009 at 15:59 UTC

    WWW::Mechanize::Link is something WWW::Mechanize gives you. I'm not sure if it's intended to be created from the outside. One thing that might or might not trip you up is that maybe your creation of the link does not create the link as a POST form but a GET form, and then ->put gets confused. I can only recommend looking at the things either using a network sniffer or, alternatively, looking at things through the debug callbacks that LWP now offers to see the difference between the two.

      thanks for reply, Corion.

      This is from WWW::Mechanize documentation for both put() and get(): $uri can be a well-formed URI string, a URI object, or a WWW::Mechanize::Link object.

      I thought this means I can create this object and pass it in, no?

        In theory maybe you can create one, but I'm not sure that what you create also is what the receiving website expects. Hence you need to compare the two, because we cannot do that for you.

Re: WWW::Mechanize::Link - how to?
by poolpi (Hermit) on Feb 17, 2009 at 08:03 UTC

    • the attr key in the constructor, is waiting for a HASHREF not a ARRAYREF.
    • the constructor lacks some keys.

    my $link = WWW::Mechanize::Link->new( { url => 'http://www.website.com/report/runreport/30', text => 'report', name => '', tag => 'a', base => 'http://www.website.com', attr => { 'fields[xxx.name]' => 'a name', 'fields[xxx.version]' => '5.34' }, } ); __END__ attr => $attr_href


    hth,
    PooLpi

    'Ebry haffa hoe hab im tik a bush'. Jamaican proverb
      ahh, thanks! after Corion's reply I figured i probably needed to fill more data, but haven't had a chance to try it yet. and i'm still learning refs (i actually thought this was an original and the only problem in my code).