Codebase list libdata-visitor-perl / 612f578
revisiting of changed aggregate structures Yuval Kogman 18 years ago
2 changed file(s) with 18 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
4242
4343 sub visit_hash {
4444 my ( $self, $data ) = @_;
45 $self->SUPER::visit_hash( $self->callback( hash => $data ) );
45 my $new_data = $self->callback( hash => $data );
46 if ( ref $data eq ref $new_data ) {
47 $self->SUPER::visit_hash( $new_data );
48 } else {
49 $self->SUPER::visit( $new_data );
50 }
4651 }
4752
4853 sub visit_array {
4954 my ( $self, $data ) = @_;
50 $self->SUPER::visit_array( $self->callback( array => $data ) );
55 my $new_data = $self->callback( array => $data );
56 if ( ref $data eq ref $new_data ) {
57 $self->SUPER::visit_array( $new_data );
58 } else {
59 $self->SUPER::visit( $new_data );
60 }
5161 }
5262
5363 sub callback {
22 use strict;
33 use warnings;
44
5 use Test::More tests => 3;
5 use Test::More tests => 4;
66
77
88 my $m; use ok $m = "Data::Visitor::Callback";
2828 }, "values were modified" );
2929
3030 is( $_, "original", '$_ unchanged in outer scope');
31
32 $o->callbacks->{hash} = sub { $_ = "value" };
33 $o->visit( $structure );
34 is( $structure, "value", "entire structure can also be changed");
35