Slides for the talk because at lpw-2011
-
Because.
-
-
But
first.
-
A word to
our sponsors.
-
Bytemark
-
Next time,
one slide.
-
"Our hosting
is way better
than our
presentations."
-
-
Because.
-
Because
Damian said
he'd use it.
-
-
Devel::Declare
-
method foo {
-
Original
version
-
Trapped sub
calls to
'method'
-
method main {
-
main->method
-
method strict
-
argh
-
Current
version
-
Traps CONST
op construction
-
Has to fight
to not match
"method"
-
Wins.
-
But ew.
-
XS
-
People get
confused
-
Why is
Devel::Declare
better than
a filter?
-
Token
sensitivity
-
Line
based
-
Hmm.
-
toke.c
-
newCVREF(0, newGVOP(OP_GV, 0, gv));
-
That takes
a reference!
-
So ...
-
B::svref_2object(
$glob_ref
)->REFCNT;
-
Filter::Util::Call
-
if ($line =~ s/method (${name_chars})//) {
return $1;
}
-
But a filter
is called
until it
returns
a line
-
EXCEPT
-
return 0; # eof
-
Then we don't
get called
anymore
-
filter_add($self);
return 0;
-
if ($new_refcount > $orig_refcount) {
$line =~ s/{/; sub ${name} { my \$self = shift;/;
}
-
method foo {
...
}
-
method foo; sub foo { my $self = shift;
...
}
-
But what
about
method main?
-
sub method (*) {
-
* proto
means
glob
-
barewords are
allowed for
globs
-
set_prototype(
\&sub, '*;@'
);
-
(our $Kw = Filter::Keyword->new(
parser => {
target_package => __PACKAGE__,
keyword_name => 'method',
parser => $parser,
},
))->install;
-
sub {
my $obj = shift;
if (my ($stripped, $matches) = $obj->match_source('', '{')) {
my $name = $obj->current_match->[0];
$stripped =~ s/{/; sub ${name} { my \$self = shift;/;
return ($stripped, 1);
} else {
return ('', 1);
}
}
-
method main { ref($self) }
-
method main { ref($self) }
my $x = "method foo bar baz";
-
method main { ref($self) }
my $x = "method foo bar baz";
warn __PACKAGE__->main;
-
main at t/simple.t line 30
-
Keywords ...
in pure perl.
-
Now we can
write
MooX::Declare!
-
Filter::Keyword
-
Filter::Keyword
git://git.shadowcat.co.uk/p5sagit/Filter-Keyword.git
-
Don't do
anything
Damian
wouldn't do.
-
Thank You
IRC:mst
mst@shadowcat.co.uk
@shadowcat_mst