[Pdx-pm] File-Fu overloading
Eric Wilhelm
scratchcomputing at gmail.com
Sat Feb 23 16:59:53 PST 2008
# from Aristotle Pagaltzis
# on Saturday 23 February 2008 14:48:
>I find the basic File::Fu interface interesting… but operator
>overloading always makes me just ever so slightly queasy, and
>this example is no exception.
Is that because of the syntax, the concepts, or the fact that perl5
doesn't quite get it right? Does it help to know that error messages
will be plentiful and informative? (Not to mention the aforementioned
disambiguation between mutations and stringifications.)
>I get the desire for syntactic
>sugar, I really do… but looking at this, I think the sane way
>to accommodate that desire is to attach overloaded semantics
>to a specially denoted scope rather than hang them off the type
>of an object.
I can't picture that without an example. I suspect though that having
the object carry the semantics around with it is still going to be
preferred.
The essential motivation is that "if I can't make this interface work,
I'm just going to slap strings together and be done with it." The
converse is that if I can make this interface work then cross-platform
pathname compatibility becomes far less tedious.
Consider the "load a group of files to be found in a given directory"
task:
my $dir = File::Fu->dir("foo");
...
foreach my $fn (qw(bar baz bat)) {
my $file = $dir + $fn;
my $fh = $file->open;
while(my $line = <$fh>) {
...
}
}
If you're uncomfortable with the lexical distance, you could put the
dir() constructor inside (or next to) the loop, but that (IMO) places
too much importance on the "specialness" of $dir. I'm looking at it
from the point of view that something named "$dir" which _isn't_ a
File::Fu::Dir is an anomaly.
--Eric
--
hobgoblin n 1: (folklore) a small grotesque supernatural creature that
makes trouble for human beings
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------
More information about the Pdx-pm-list
mailing list