POE-XUL

 view release on metacpan or  search on metacpan

lib/POE/XUL/ChangeManager.pm  view on Meta::CPAN

##############################################################
sub after_style_change
{
    my( $self, $style, $property, $value ) = @_;
    my $state = $self->{states}{ 0+$style };
    $state->style_change( $property, $value );
}

##############################################################
# when node added, set parent node state id on child node state
sub after__add_child_at_index
{
    my( $self, $parent, $child, $index ) = @_;

    my $child_state = $self->node_state( $child );
    $child_state->{parent} = $self->node_state( $parent );
    weaken $child_state->{parent};
    if( defined $child_state->{trueindex} ) {
        $child_state->{trueindex} = $index;
    }
    else {
        $child_state->{index} = $index;
    }

    return unless @{$child->{children} || []};

    my $n = 0;
    foreach my $subchild ( @{ $child->{children} } ) {
        $self->after__add_child_at_index( $child, $subchild, $n );
        $n++;
    }
}

sub set_trueindex
{
    my( $self, $parent, $child, $trueindex ) = @_;
    my $child_state = $self->node_state( $child );
    # Ignore trueindex for now...  It breaks to many things
    $child_state->{index} = $trueindex;
}

##############################################################
# when node destroyed, update state using set_destoyed
sub before_remove_child
{
    my( $self, $parent, $child, $index ) = @_;
#	my $child       = $parent->_compute_child_and_index($context->params->[1]);
    # return unless $child;
    Carp::croak "Why no index" unless defined $index;
    my $child_state = $self->node_state($child);
    $child_state->is_destroyed( $parent, $index );
    push @{$self->{destroyed}}, $child_state;

    delete $self->{states}{ "$child" };
    delete $self->{states}{ $child_state->{style} }
                            if $child_state->{style};
    $self->unregister_node( $child_state->{id}, $child );
}

##############################################################
sub after_cdata_change
{
    my( $self, $node ) = @_;
    my $state = $self->node_state( $node );
    $state->{cdata} = $node->{data};
    $state->{is_new} = 1;
}



##############################################################
# So that we can detect changes between requests
sub request_start
{
    my( $self, $event ) = @_;
    $self->{current_event} = $event;
    $self->{responded} = 0;
}

sub request_done
{
    my( $self ) = @_;
    $self->{responded} = 1;
    my $event = delete $self->{current_event};
    $event->dispose if $event;
    undef( $event );

#    use Devel::Cycle;
#    find_cycle( $self );
}

##############################################################
sub wrapped_error
{
    my( $self, $string ) = @_;
    if( $self->{current_event} ) {
        # xwarn "wrapped with $self->{current_event}";
        $self->error_response( $self->{current_event}->response, $string );
    }
    else {
        # TODO: what to do with errors that happen between events?
        xlog "Error between events: $string";
    }
}

##############################################################
sub error_response
{
    my( $self, $resp, $string ) = @_;
    xlog "error_response $string";
    # confess "ERROR $string";
    return $self->cooked_response( $resp, [[ 'ERROR', '', $string]] );
}

##############################################################
sub response
{
    my( $self, $resp ) = @_;
    my $out = $self->flush;
    # xwarn "response = ", 0+@$out;
    $self->cooked_response( $resp, $out );
}

##############################################################
sub cooked_response



( run in 3.067 seconds using v1.01-cache-2.11-cpan-0d23b851a93 )