views:

90

answers:

3

While reading the snippets provided by FormFiller ( where I kinda got by accident ) , I noticed this line:

$f->add_filler( password => Interactive => []);

Is this password => Interactive => [] equivalent to {"password" => {"Interactive"=>[]}}? If not, what does it become?

+7  A: 

=> is semantically (almost) identical to , (see "Comma operator" at perldoc perlop), so you're doing this:

$f->add_filler( 'password', 'Interactive', [] );

If this calling style is supported by the method (which it doesn't), then it itself would have to convert these arguments into

{ password => { Interactive => [] } }

However more typically, hash-style arguments would be passed as a legal hash to begin with:

$f->add_filler( password => { Interactive => 1 } );

This would be received by the function like this:

sub add_filler
{
    my $this = shift;
    my %configs = @_;
    # ...
}
Ether
Yeah, but if you only send a method `password => "Interactive"`, then the method would see that as a single argument, in the form of a hashref, right?
Geo
No, that's still sending two arguments. The method can choose to interpret those arguments as a hash by reading the argument list into a hash rather than an array: `my $this = shift; my %config = @_;`
Ether
You should probably remove everything after that first code block in your answer, because it's only confusing the issue. The `add_filler` function *doesn't* do any hash magic. More specifically, it does this: `my ($self,$name,$class,@args) = @_;` (see here: http://cpansearch.perl.org/src/CORION/WWW-Mechanize-FormFiller-0.10/lib/WWW/Mechanize/FormFiller.pm). So it only uses the `=>` operator for its automatic string-interpreting properties.
mercator
+5  A: 

No, it's exactly the same as

$f->add_filler( "password", "Interactive", []);
Dave Hinton
+4  A: 

The Data::Dumper module is great for answering questions like this. Use the following mock:

package Foo;
use Data::Dumper;
sub new { bless {} => shift }
sub add_filler {
  my $self = shift;
  print Dumper \@_;
}

Then call it

package main;
my $f = Foo->new;
$f->add_filler( password => Interactive => []);

and see when you get:

$VAR1 = [
          'password',
          'Interactive',
          []
        ];

This shows that add_filler receives a flat list of three arguments: two strings and a reference to an anonymous array.

Greg Bacon