in reply to Re^5: Use method/function signatures with Perl
in thread Use method/function signatures with Perl
Now I understand what you're asking. You're actually dealing with some interesting stuff here, but I think that most of the concern is a theoretical non-issue, but in practice it is an issue, but I think we're looking at it slightly differently. For example, your initial code doesn't work:
sub foo(ARRAY $bar) {...} # later foo(Bar->new);
That breaks immediately because &foo is expecting an ARRAY, not an object of class Bar. It's an easy fix:
sub foo(Bar $bar) {...}Now it doesn't matter how someone implements Bar internally. However, there is one (false) objection and one very real objection. The false objection is this:
sub foo(Bar $bar) { print $bar->[3]; }
Obviously, violating encapsulation is going to cause problems regardless of whether or not method signatures are implemented. The real problem, however, and I think this is what you're getting at, lies in this:
my $parser = HTML::TokeParser->new(\$html); sub foo(ARRAY $token) {...} foo($parser->get_token) {...}
HTML::TokeParser returns array references. However, what if someone wants to use HTML::TokeParser::Simple? That module blesses the references. As a result, it is no longer a drop-in replacement. I am forced to alter the above code. (And this just highlighted a bug in my code that I'll have to fix ASAP -- darn.)
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Use method/function signatures with Perl
by dragonchild (Archbishop) on Dec 06, 2004 at 16:40 UTC |