On Fri, 22 Apr 2005 11:42:10 -0400, Larry Wall <larry@wall.org> wrote: > > You speak of "open" as if it must be a single function. We're now > living in the age of MMD, so what you're asking for is a no-brainer. > If we decided to we could even do MMD with constraints: > > multi sub open ($u of Str where /^file:/, *@opts) returns Handle > {...} > multi sub open ($u of Str where /^http:/, *@opts) returns Handle > {...} > multi sub open ($u of Str where /^ftp:/, *@opts) returns Handle {...} > multi sub open ($u of Str where /^mailto:/, *@opts) returns Handle > {...} > ... > > Though that would potentially be problematic if you wanted to open > a file whose name started with "http:", so we'd probably want to > give that suite of multis a different name. Call it io() maybe, if > we can unify the Handle and IO abstractions. As I've said before, > I kinda like the IO::All module, except for how it overloads < and >. > But Perl 6 has ==> and <== that can do that instead, which just happen > to be called "pipes", strange coincidence. :-) Well why can't you define the functions like so: multi sub open ($u of Str where /^file:\/\//, *@opts) returns Handle {...} multi sub open ($u of Str where /^http:\/\//, *@opts) returns Handle {...} multi sub open ($u of Str where /^ftp:\/\//, *@opts) returns Handle {...} multi sub open ($u of Str where /^mailto:\/\//, *@opts) returns Handle {...} Also, I don't know much about rules with regex yet, but could you do something like... multi sub open ($u of Str where /<protocol(file)>/, *@opts) returns Handle {...} Where < <protocol(file)> > expands to < file:// >Thread Previous | Thread Next