Thank you David for the reply and comment. I'll just explicitly comment what
I did.
On Wed, Sep 10, 2008 at 1:28 PM, David Precious <[EMAIL PROTECTED]>wrote:
> sawyer x wrote:
>
>> As you can see, I've added two lines to check what's wrong with the value.
>> I tried different things, till I decided to check it with Data::Dumper.
>> Low and behold, it returns an object. Here is the output:
>> site_name: $VAR1 = bless( {
>> 'success' => 1,
>> 'handled' => 1,
>> 'set_val' => 0,
>> 'value' => 'hello.com',
>> 'context' => 27
>> }, 'IO::Prompt::ReturnVal' );
>>
>> Obviously if I would remember TFM after RTFM I would know this by heart.
>>
>> Still, maybe there should be a method, or parameter (IO::Prompt
>> already uses a lot of those) that indicates it shouldn't return an
>> object, but a simple string?
>> Right now I changed the code to:
>> while (!is_domain($site_name)) {
>> $site_name = prompt('Please enter a valid hostname: ')->{value};
>> }
>> and it works perfectly.
>>
>
> The IO::Prompt::ReturnVal object should stringify to the value provided.
>
> while (my $obj = IO::Prompt::prompt("say something: ")) {
> print "You said $obj\n";
> }
>
> The problem you're seeing is that Data::Validate::Domain assumes that, if
> its first argument is a reference, it's being used OO-style, and stores it
> in $self. It then has no domain to look at.
>
> I think changing IO::Prompt to have an additional option is probably a
> waste of time; after all, you won't know about the option unless you read
> the docs, and if you read the docs, you'll know that you get back an
> IO::Prompt::ReturnVal object, which stringifies as you'd expect :)
>
> You could fix your code simply by changing is_domain($site_name) to
> is_domain("$site_name") - although making it explicitly clear that you're
> fetching the value from the IO::Prompt::ReturnVal object is probably better
> coding, in that future programmers won't look at it, wonder why the hell you
> bothered to double-quote a scalar, then find it breaks when they remove the
> quotes. (Nothing a suitable comment wouldn't solve though).
>
> Cheers
>
> Dave P
>
>