r8141 - in /branches/upstream/libdata-visitor-perl/current: Changes META.yml SIGNATURE lib/Data/Visitor.pm lib/Data/Visitor/Callback.pm t/base.t t/callback.t

gregoa-guest at users.alioth.debian.org gregoa-guest at users.alioth.debian.org
Tue Oct 9 18:26:11 UTC 2007


Author: gregoa-guest
Date: Tue Oct  9 18:26:11 2007
New Revision: 8141

URL: http://svn.debian.org/wsvn/?sc=1&rev=8141
Log:
[svn-upgrade] Integrating new upstream version, libdata-visitor-perl (0.09)

Modified:
    branches/upstream/libdata-visitor-perl/current/Changes
    branches/upstream/libdata-visitor-perl/current/META.yml
    branches/upstream/libdata-visitor-perl/current/SIGNATURE
    branches/upstream/libdata-visitor-perl/current/lib/Data/Visitor.pm
    branches/upstream/libdata-visitor-perl/current/lib/Data/Visitor/Callback.pm
    branches/upstream/libdata-visitor-perl/current/t/base.t
    branches/upstream/libdata-visitor-perl/current/t/callback.t

Modified: branches/upstream/libdata-visitor-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libdata-visitor-perl/current/Changes?rev=8141&op=diff
==============================================================================
--- branches/upstream/libdata-visitor-perl/current/Changes (original)
+++ branches/upstream/libdata-visitor-perl/current/Changes Tue Oct  9 18:26:11 2007
@@ -1,3 +1,6 @@
+0.09
+	- add visit_hash_entry and visit_array_entry
+
 0.08
 	- add retain_magic and use it to keep blessedness of mapped objects that
 	  were forced into being visited by "regular" ref visitor methods

Modified: branches/upstream/libdata-visitor-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libdata-visitor-perl/current/META.yml?rev=8141&op=diff
==============================================================================
--- branches/upstream/libdata-visitor-perl/current/META.yml (original)
+++ branches/upstream/libdata-visitor-perl/current/META.yml Tue Oct  9 18:26:11 2007
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:                Data-Visitor
-version:             0.08
+version:             0.09
 abstract:            ~
 license:             ~
 generated_by:        ExtUtils::MakeMaker version 6.32

Modified: branches/upstream/libdata-visitor-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/branches/upstream/libdata-visitor-perl/current/SIGNATURE?rev=8141&op=diff
==============================================================================
--- branches/upstream/libdata-visitor-perl/current/SIGNATURE (original)
+++ branches/upstream/libdata-visitor-perl/current/SIGNATURE Tue Oct  9 18:26:11 2007
@@ -14,23 +14,23 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-SHA1 dca53d93193ba234d36fe458a34a22935c0ec0b8 Changes
+SHA1 a5cff2c8fcbcf93991fa554379ba5f1698be76fd Changes
 SHA1 adbdb1d57cfa058d1ced16b5767527d0dfb6a253 MANIFEST
 SHA1 ddb918d4e02cc06f4b9fe77adeca65403f8fdd56 MANIFEST.SKIP
-SHA1 95e533a541a400b08002b2490c4921764b4c9850 META.yml
+SHA1 c3fe5f0877ea45b9469805ffd5404471dc99a889 META.yml
 SHA1 7e820fe45a90871dcc686bd3ffd7897444a6ea30 Makefile.PL
-SHA1 352cc099c97b13df7b481ad5a6ba6570d535e85a lib/Data/Visitor.pm
-SHA1 d8ad6965a7e366bfe68c72f7139d606a71fe1a90 lib/Data/Visitor/Callback.pm
-SHA1 3180f412df2834d1f1c9290e9b8726d0b374afc2 t/base.t
+SHA1 5274ce8ed2b538a82ddb1131a24cdb2c992e4920 lib/Data/Visitor.pm
+SHA1 909ce30088a2be5675c7ec0c7e0299dfdbc06d7a lib/Data/Visitor/Callback.pm
+SHA1 dfba09a3df7adaf6d0369a4745e6e336272c405d t/base.t
 SHA1 257c858e1bc12c1039e93cac62a0d37f2e0d804d t/bugs.t
-SHA1 2ddc55b7127db5216879fce4c165b360923eca18 t/callback.t
+SHA1 74100f842ec1699a35958a59c39d434a84dfc501 t/callback.t
 SHA1 7e59409671d0147236beef17a6dfdc0997d6a97a t/callback_aliasing.t
 SHA1 9f6dff4facaf491f3776fec263d13acd4448de33 t/circular_refs.t
 SHA1 54affd2088fa25d8eec562fb8d39e1abd0d123c7 t/globs.t
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.7 (Darwin)
 
-iD8DBQFGiAZTVCwRwOvSdBgRAvneAJ0XffiTdaj8HDZZPVvT24h2ruE2WgCgkOyQ
-htgwmeZ0sb3o0nmFSUGhYJk=
-=AvZo
+iD8DBQFHCWHzVCwRwOvSdBgRAtHfAJ9iQFFsizOH/MoJl7ELAevVJSKqUACZAXO0
+UrVHeFU9HKod5jYodLrt0SY=
+=YwOY
 -----END PGP SIGNATURE-----

Modified: branches/upstream/libdata-visitor-perl/current/lib/Data/Visitor.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libdata-visitor-perl/current/lib/Data/Visitor.pm?rev=8141&op=diff
==============================================================================
--- branches/upstream/libdata-visitor-perl/current/lib/Data/Visitor.pm (original)
+++ branches/upstream/libdata-visitor-perl/current/lib/Data/Visitor.pm Tue Oct  9 18:26:11 2007
@@ -10,7 +10,7 @@
 use overload ();
 use Symbol ();
 
-our $VERSION = "0.08";
+our $VERSION = "0.09";
 
 sub visit {
 	my ( $self, $data ) = @_;
@@ -77,20 +77,46 @@
 	my ( $self, $hash ) = @_;
 
 	if ( not defined wantarray ) {
-		$self->visit( $_ ) for ( values %$hash );
+		foreach my $key ( keys %$hash ) {
+			$self->visit_hash_entry( $key, $hash->{$key}, $hash );
+		}
 	} else {
-		return $self->retain_magic( $hash, { map { $_ => $self->visit( $hash->{$_} ) } keys %$hash } );
-	}
+		return $self->retain_magic( $hash, { map { $self->visit_hash_entry( $_, $hash->{$_}, $hash ) } keys %$hash } );
+	}
+}
+
+sub visit_hash_entry {
+	my ( $self, $key, $value, $hash ) = @_;
+
+	return (
+		$self->visit_hash_key($key,$value,$hash),
+		$self->visit_hash_value($_[2],$key,$hash) # retain aliasing semantics
+	);
+}
+
+sub visit_hash_key {
+	my ( $self, $key, $value, $hash ) = @_;
+	$self->visit($key);
+}
+
+sub visit_hash_value {
+	my ( $self, $value, $key, $hash ) = @_;
+	$self->visit($_[1]); # retain it's aliasing semantics
 }
 
 sub visit_array {
 	my ( $self, $array ) = @_;
 
 	if ( not defined wantarray ) {
-		$self->visit( $_ ) for @$array;	
+		$self->visit_array_entry( $array->[$_], $_, $array ) for 0 .. $#$array
 	} else {
-		return $self->retain_magic( $array, [ map { $self->visit( $_ ) } @$array ] );
-	}
+		return $self->retain_magic( $array, [ map { $self->visit_array_entry( $array->[$_], $_, $array ) } 0 .. $#$array ] );
+	}
+}
+
+sub visit_array_entry {
+	my ( $self, $value, $index, $array ) = @_;
+	$self->visit($_[1]);
 }
 
 sub visit_scalar {
@@ -182,6 +208,16 @@
 If the value is a blessed object, C<visit> calls this method. The base
 implementation will just forward to C<visit_value>.
 
+=item visit_ref $value
+
+Generic recursive visitor. All non blessed values are given to this.
+
+C<visit_object> can delegate to this method in order to visit the object
+anyway.
+
+This will check if the visitor can handle C<visit_$reftype> (lowercase), and if
+not delegate to C<visit_value> instead.
+
 =item visit_array $array_ref
 
 =item visit_hash $hash_ref
@@ -196,6 +232,24 @@
 
 If the value is anything else, this method is called. The base implementation
 will return $value.
+
+=item visit_hash_entry $key, $value, $hash
+
+Delegates to C<visit_hash_key> and C<visit_hash_value>. The value is passed as
+C<$_[2]> so that it is aliased.
+
+=item visit_hash_key $key, $value, $hash
+
+Calls C<visit> on the key and returns it.
+
+=item visit_hash_value $value, $key, $hash
+
+The value will be aliased (passed as C<$_[1]>).
+
+=item visit_array_entry $value, $index, $array
+
+Delegates to C<visit> on value. The value is passed as C<$_[1]> to retain
+aliasing.
 
 =back
 
@@ -219,7 +273,22 @@
 
 =head1 TODO
 
+=over 4
+
+=item *
+
 Add support for "natural" visiting of trees.
+
+=item *
+
+Expand C<retain_magic> to support tying at the very least, or even more with
+L<Variable::Magic> if possible.
+
+Tied values might be redirected to an alternate handler that builds a new empty
+value, and ties it to a visited clone of the object the original is tied to
+using a trampoline class. Look into this.
+
+=back
 
 =head1 SEE ALSO
 

Modified: branches/upstream/libdata-visitor-perl/current/lib/Data/Visitor/Callback.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libdata-visitor-perl/current/lib/Data/Visitor/Callback.pm?rev=8141&op=diff
==============================================================================
--- branches/upstream/libdata-visitor-perl/current/lib/Data/Visitor/Callback.pm (original)
+++ branches/upstream/libdata-visitor-perl/current/lib/Data/Visitor/Callback.pm Tue Oct  9 18:26:11 2007
@@ -152,6 +152,10 @@
 Within the callback $_ is aliased to the data, and this is also passed in the
 parameter list.
 
+Any method can also be used as a callback:
+
+	object => "visit_ref", # visit objects anyway
+
 =over 4
 
 =item visit
@@ -174,9 +178,16 @@
 
 Called for blessed objects.
 
+Since L<Data::Visitor/visit_object> will not recurse downwards unless you
+delegate to C<visit_ref>, you can specify C<visit_ref> as the callback for
+C<object> in order to enter objects.
+
+It is reccomended that you specify the classes you want though, instead of just
+visiting any object forcefully.
+
 =item Some::Class
 
-You can use any class name as a clalback. This is clled only after the
+You can use any class name as a callback. This is clled only after the
 C<object> callback.
 
 =item array

Modified: branches/upstream/libdata-visitor-perl/current/t/base.t
URL: http://svn.debian.org/wsvn/branches/upstream/libdata-visitor-perl/current/t/base.t?rev=8141&op=diff
==============================================================================
--- branches/upstream/libdata-visitor-perl/current/t/base.t (original)
+++ branches/upstream/libdata-visitor-perl/current/t/base.t Tue Oct  9 18:26:11 2007
@@ -28,6 +28,7 @@
 
 # cause logging
 $mock->set_always( $_ => "magic" ) for qw/visit_value visit_object/;
+$mock->mock( visit_hash_key => sub { $_[1] } );
 $mock->mock( visit_hash => sub { shift->Data::Visitor::visit_hash( @_ )  } );
 $mock->mock( visit_array => sub { shift->Data::Visitor::visit_array( @_ )  } );
 

Modified: branches/upstream/libdata-visitor-perl/current/t/callback.t
URL: http://svn.debian.org/wsvn/branches/upstream/libdata-visitor-perl/current/t/callback.t?rev=8141&op=diff
==============================================================================
--- branches/upstream/libdata-visitor-perl/current/t/callback.t (original)
+++ branches/upstream/libdata-visitor-perl/current/t/callback.t Tue Oct  9 18:26:11 2007
@@ -91,11 +91,11 @@
 our %FOO = ( "foo" => undef );
 
 counters_are( \*FOO, "glob", {
-	visit => 5,
+	visit => 6,
 	'scalar' => 1,
 	hash => 1,
-	value => 2,
-	plain_value => 2,
+	value => 3,
+	plain_value => 3,
 	'glob' => 1,
 });
 




More information about the Pkg-perl-cvs-commits mailing list