Damian starting talking about Perl magic, for instance
package MyClass
use Sub::CallAsMethod;
sub foo
my $self = shift;
bar(); # rather than $self->bar();
}
The interface to
Sub::CallAsMethod
is as minial as possible, non-existant in fact, the module's effect is as indistinguishable from magic.
The existance of these sorts of modules isn't new, it's been around for some time. The main problem with them is
use strict
which normally breaks, although of course use diagnostics
is worse "not only are you executed for your sins, you're given a long lecture about it first".
A good example of a magical module is
IO::All
which is definately sufficiently advanced, it's magic, but given a sufficently easy mind there isn't any technology that can't be pushed too far. Damian has extended IO::All to do this,
use IO::All::Pulp::Fiction;
my @array = <~/file.txt>;
Also
Perl6::Say
which will add the newline automatically to print
statements so long as $/
isn't definied. If you want to find sufficiently advanced technology, look in the Perl6 namespace.
Sufficently advanced technology doesn't have to appear our of thin air, find the bits of your code that annoy you, and then auto-magically hide them so you'll never have to do it again. For instance look at Damian's
IO::Prompt
module
use IO::Prompt;
while( prompt "next: " ) {
print "Ypu said 'S_'\n";
}
Also, comments, comments are passive and boring. they don't really pull their weight. So Damian decided that comments should be interactive and useful, last year he demo'ed a module
IO::Progress
to construct progress bars, but he hasn't used it, it wasn't sufficiently advanced. The interface wasn't magical enough. So he wote Smart::Comments
. Here you comment each initialisation step with a picture of what you'd like printed out to the progress bar (while loops even have exponential slow downs). Smart::Comments
uses source filtering since tehre aren't any hooks in Perl 5 to interogate the comments.
use Smart::Comments;
for my $i ( 1..10) { ### Looping... done
...
}
The module can also do things like,
###check: $i == 10;
they aren't smart comments unless they're smart.
Then he started talking about his new version of
Lingua::Inflect
which has so much magic I can't even fit the explanation in the space provided.
Perl's stringths are that it does the heavy lifting for you. Damian argues that you should make that the strength of your own modules, we should think about what we can remove from the interface of our modules to make them simpler to use, almost magic infact.