From ce0ce002223ca83946204e78bea5c178c6808e5c Mon Sep 17 00:00:00 2001 From: matthewt Date: Fri, 9 Nov 2007 13:53:40 +0000 Subject: replace renders with fragment --- Makefile.PL | 1 + lib/Reaction/UI/WidgetClass.pm | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index aec5ca2..05fb324 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -28,6 +28,7 @@ requires 'Email::Send'; requires 'Email::MIME'; requires 'Email::MIME::Creator'; requires 'Text::CSV_XS'; +requires 'Devel::Declare' => '0.001004'; catalyst; diff --git a/lib/Reaction/UI/WidgetClass.pm b/lib/Reaction/UI/WidgetClass.pm index 83e3076..413b7cf 100644 --- a/lib/Reaction/UI/WidgetClass.pm +++ b/lib/Reaction/UI/WidgetClass.pm @@ -4,6 +4,7 @@ use Reaction::ClassExporter; use Reaction::Class; use Reaction::UI::Widget; use Data::Dumper; +use Devel::Declare; no warnings 'once'; @@ -23,6 +24,21 @@ class WidgetClass, which { }, # XXX zis is not ze grand design. OBSERVABLE. string => sub (&) { -string => [ @_ ] }, # meh (maybe &;@ later?) wrap => sub { $self->do_wrap_sub($package, @_); }, # should have class. + fragment => sub (@) { }, # placeholder rewritten by do_import + ); + }; + + after do_import => sub { + my ($self, $pkg, $args) = @_; + + Devel::Declare->install_declarator( + $pkg, 'fragment', DECLARE_NAME, + sub { }, + sub { + our $FRAGMENT_CLOSURE; + splice(@_, 1, 1); # remove undef proto arg + $FRAGMENT_CLOSURE->(@_); + } ); }; @@ -31,12 +47,16 @@ class WidgetClass, which { overrides do_class_sub => sub { my ($self, $package, $class) = @_; # intercepts 'foo renders ...' - local *renders::AUTOLOAD = sub { - our $AUTOLOAD; - shift; - $AUTOLOAD =~ /^renders::(.*)$/; - $self->do_renders_meth($package, $class, $1, @_); + our $FRAGMENT_CLOSURE; + local $FRAGMENT_CLOSURE = sub { + $self->do_renders_meth($package, $class, @_); }; + #local *renders::AUTOLOAD = sub { + # our $AUTOLOAD; + # shift; + # $AUTOLOAD =~ /^renders::(.*)$/; + # $self->do_renders_meth($package, $class, $1, @_); + #}; # intercepts 'foo over ...' local *over::AUTOLOAD = sub { our $AUTOLOAD; -- cgit v1.2.3-54-g00ecf