Chandra

 view release on metacpan or  search on metacpan

lib/Chandra/Component.pm  view on Meta::CPAN

        $app->eval("var _e=document.getElementById('$cid');if(_e)_e.remove();");
    }

    comp__mounted $self, 0;
    comp__app $self, undef;
    delete $_comp_registry{$cid};

    return $self;
}

sub update {
    my ($self) = @_;
    my $app = comp__app $self;
    return $self unless $app && comp__mounted $self;

    my $cid = $self->_ensure_cid;
    my $inner = $self->_render_inner;
    $app->update("#$cid", $inner);

    $self->on_update if $self->can('on_update');

    return $self;
}

# Update only a sub-section of the component by a stable CSS selector.
# The selector is relative to the component's root element.
# The $html should already have actions rewritten.
sub update_part {
    my ($self, $sub_id, $html) = @_;
    my $app = comp__app $self;
    return $self unless $app && comp__mounted $self;

    $html = $self->_rewrite_actions($html);
    $app->update("#$sub_id", $html);

    return $self;
}

t/96_components.t  view on Meta::CPAN

use Chandra::Breadcrumb;
use Chandra::Table;
use Chandra::Form;
use Chandra::Form::Validator;

# An app that records what the components ask of it.
package MockCompApp;
our (%bound, @updates, @evals, @navigated, @css);
sub new { bless {}, shift }
sub bind { my ($self, $name, $code) = @_; $bound{$name} = $code; return $self }
sub update { my ($self, $sel, $html) = @_; push @updates, [$sel, $html]; return $self }
sub eval { my ($self, $js) = @_; push @evals, $js; return 1 }
sub navigate { my ($self, $route) = @_; push @navigated, $route; return $self }
sub css { my ($self, $css) = @_; push @css, $css; return $self }

package MockNoNav;
sub new { bless {}, shift }
sub bind { $_[0] }
sub update { $_[0] }
sub eval { 1 }

package Widget;
use Object::Proto;
BEGIN {
    Object::Proto::define('Widget', extends => 'Chandra::Component', 'label:Str:default(w)');
    Object::Proto::import_accessors('Widget');
}
our @events;
sub render { my ($self) = @_; return '<div class="widget"><button data-action="poke:1">' . $self->label . '</button><input data-action="typed"><select data-action="picked"></select></div>' }

t/99_branches.t  view on Meta::CPAN

sub exit             { $_[0]{exits}++ }
sub terminate        { $_[0]{terminated}++ }
sub bind             { $_[0]{bound}{ $_[1] } = $_[2] }
sub set_title        { push @{ $_[0]{titles} }, $_[1] }
sub title            { 'Mock' }

package MockCompApp;
our @updates;
sub new { bless {}, shift }
sub bind { $_[0] }
sub update { my ($self, $sel, $html) = @_; push @updates, [$sel, $html]; return $self }
sub eval { 1 }

package main;

my @warned;
local $SIG{__WARN__} = sub { push @warned, $_[0] };

sub mock_app {
    my %o = @_;
    my $app = Chandra::App->new(title => 'Branches');



( run in 2.896 seconds using v1.01-cache-2.11-cpan-145b269f2f3 )