r37117 - in /branches/upstream/libmoosex-blessed-reconstruct-perl: ./ current/ current/lib/ current/lib/MooseX/ current/lib/MooseX/Blessed/ current/t/

franck-guest at users.alioth.debian.org franck-guest at users.alioth.debian.org
Mon Jun 1 08:51:09 UTC 2009


Author: franck-guest
Date: Mon Jun  1 08:51:04 2009
New Revision: 37117

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=37117
Log:
[svn-inject] Installing original source of libmoosex-blessed-reconstruct-perl

Added:
    branches/upstream/libmoosex-blessed-reconstruct-perl/
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/Changes
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/MANIFEST
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/MANIFEST.SKIP
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/META.yml
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/Makefile.PL
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/SIGNATURE
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/lib/
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/lib/MooseX/
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/lib/MooseX/Blessed/
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/lib/MooseX/Blessed/Reconstruct.pm
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/t/
    branches/upstream/libmoosex-blessed-reconstruct-perl/current/t/basic.t

Added: branches/upstream/libmoosex-blessed-reconstruct-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-blessed-reconstruct-perl/current/Changes?rev=37117&op=file
==============================================================================
--- branches/upstream/libmoosex-blessed-reconstruct-perl/current/Changes (added)
+++ branches/upstream/libmoosex-blessed-reconstruct-perl/current/Changes Mon Jun  1 08:51:04 2009
@@ -1,0 +1,6 @@
+0.02
+	- Remove Class::Accessor from test suite (not having it as a dependency
+	  caused failures)
+
+0.01
+	- Initial release

Added: branches/upstream/libmoosex-blessed-reconstruct-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-blessed-reconstruct-perl/current/MANIFEST?rev=37117&op=file
==============================================================================
--- branches/upstream/libmoosex-blessed-reconstruct-perl/current/MANIFEST (added)
+++ branches/upstream/libmoosex-blessed-reconstruct-perl/current/MANIFEST Mon Jun  1 08:51:04 2009
@@ -1,0 +1,8 @@
+Changes
+lib/MooseX/Blessed/Reconstruct.pm
+Makefile.PL
+MANIFEST			This list of files
+MANIFEST.SKIP
+t/basic.t
+META.yml                                 Module meta-data (added by MakeMaker)
+SIGNATURE                                Public-key signature (added by MakeMaker)

Added: branches/upstream/libmoosex-blessed-reconstruct-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-blessed-reconstruct-perl/current/MANIFEST.SKIP?rev=37117&op=file
==============================================================================
--- branches/upstream/libmoosex-blessed-reconstruct-perl/current/MANIFEST.SKIP (added)
+++ branches/upstream/libmoosex-blessed-reconstruct-perl/current/MANIFEST.SKIP Mon Jun  1 08:51:04 2009
@@ -1,0 +1,44 @@
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+\bSCCS\b
+,v$
+\B\.svn\b
+\B\.git\b
+\b_darcs\b
+
+# Avoid Makemaker generated and utility files.
+\bMANIFEST\.bak
+\bMakefile$
+\bblib/
+\bMakeMaker-\d
+\bpm_to_blib\.ts$
+\bpm_to_blib$
+\bblibdirs\.ts$         # 6.18 through 6.25 generated this
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build/
+
+# Avoid temp and backup files.
+~$
+\.old$
+\#$
+\b\.#
+\.bak$
+
+# Avoid Devel::Cover files.
+\bcover_db\b
+
+### DEFAULT MANIFEST.SKIP ENDS HERE ####
+
+\.DS_Store$
+\.sw.$
+(\w+-)*(\w+)-\d\.\d+(?:\.tar\.gz)?$
+
+\.t\.log$
+
+\.prove$
+
+# XS shit
+\.(?:bs|c|o)$

Added: branches/upstream/libmoosex-blessed-reconstruct-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-blessed-reconstruct-perl/current/META.yml?rev=37117&op=file
==============================================================================
--- branches/upstream/libmoosex-blessed-reconstruct-perl/current/META.yml (added)
+++ branches/upstream/libmoosex-blessed-reconstruct-perl/current/META.yml Mon Jun  1 08:51:04 2009
@@ -1,0 +1,23 @@
+--- #YAML:1.0
+name:               MooseX-Blessed-Reconstruct
+version:            0.02
+abstract:           ~
+author:  []
+license:            unknown
+distribution_type:  module
+configure_requires:
+    ExtUtils::MakeMaker:  0
+requires:
+    Class::MOP:        0.66
+    Data::Visitor:     0.21
+    Moose:             0
+    namespace::clean:  0
+    Test::use::ok:     0
+no_index:
+    directory:
+        - t
+        - inc
+generated_by:       ExtUtils::MakeMaker version 6.48
+meta-spec:
+    url:      http://module-build.sourceforge.net/META-spec-v1.4.html
+    version:  1.4

Added: branches/upstream/libmoosex-blessed-reconstruct-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-blessed-reconstruct-perl/current/Makefile.PL?rev=37117&op=file
==============================================================================
--- branches/upstream/libmoosex-blessed-reconstruct-perl/current/Makefile.PL (added)
+++ branches/upstream/libmoosex-blessed-reconstruct-perl/current/Makefile.PL Mon Jun  1 08:51:04 2009
@@ -1,0 +1,21 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+	NAME         => 'MooseX::Blessed::Reconstruct',
+	VERSION_FROM => 'lib/MooseX/Blessed/Reconstruct.pm',
+	INSTALLDIRS  => 'site',
+	SIGN         => 1,
+	PL_FILES     => { },
+	PREREQ_PM    => {
+		'Test::use::ok' => 0,
+		'namespace::clean' => 0,
+		'Moose' => 0,
+		'Class::MOP' => 0.66,
+		'Data::Visitor' => 0.21,
+	},
+);
+

Added: branches/upstream/libmoosex-blessed-reconstruct-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-blessed-reconstruct-perl/current/SIGNATURE?rev=37117&op=file
==============================================================================
--- branches/upstream/libmoosex-blessed-reconstruct-perl/current/SIGNATURE (added)
+++ branches/upstream/libmoosex-blessed-reconstruct-perl/current/SIGNATURE Mon Jun  1 08:51:04 2009
@@ -1,0 +1,30 @@
+This file contains message digests of all files listed in MANIFEST,
+signed via the Module::Signature module, version 0.55.
+
+To verify the content in this distribution, first make sure you have
+Module::Signature installed, then type:
+
+    % cpansign -v
+
+It will check each file's integrity, as well as the signature's
+validity.  If "==> Signature verified OK! <==" is not displayed,
+the distribution may already have been compromised, and you should
+not run its Makefile.PL or Build.PL.
+
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+SHA1 2f6fa369e51584218ebf3554a85555877790edd7 Changes
+SHA1 78a468e5be41b2f15d15e6a989c94fba17c9a093 MANIFEST
+SHA1 190e9058eb9c6446a1a3f3ddf15b082f1ecde152 MANIFEST.SKIP
+SHA1 c08a87265b69c75d417699281563329fbcdb81f9 META.yml
+SHA1 ebac10cd7577a84ec38c669f13bc0de06be3bb5e Makefile.PL
+SHA1 030c2369c61d43c390a6ce05d80b418a2a115086 lib/MooseX/Blessed/Reconstruct.pm
+SHA1 a864e611614c3e25f55dd7174dc6f1f8922881a9 t/basic.t
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.7 (Darwin)
+
+iD8DBQFJOu6jVCwRwOvSdBgRAmKPAJ9Q5L4EnERUDF73/OVijjQr40tuygCgoam0
+FCVPdd9RgU1ArqcOSlPQhyA=
+=1yBL
+-----END PGP SIGNATURE-----

Added: branches/upstream/libmoosex-blessed-reconstruct-perl/current/lib/MooseX/Blessed/Reconstruct.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-blessed-reconstruct-perl/current/lib/MooseX/Blessed/Reconstruct.pm?rev=37117&op=file
==============================================================================
--- branches/upstream/libmoosex-blessed-reconstruct-perl/current/lib/MooseX/Blessed/Reconstruct.pm (added)
+++ branches/upstream/libmoosex-blessed-reconstruct-perl/current/lib/MooseX/Blessed/Reconstruct.pm Mon Jun  1 08:51:04 2009
@@ -1,0 +1,153 @@
+#!/usr/bin/perl
+
+package MooseX::Blessed::Reconstruct;
+use Moose;
+
+use Class::MOP 0.66; # well behaved load_class()
+use Data::Visitor 0.21; # n-arity visit
+
+use namespace::clean -except => 'meta';
+
+our $VERSION = "0.02";
+
+extends qw(Data::Visitor);
+
+has load_classes => (
+	isa => "Bool",
+	is  => "rw",
+	default => 1,
+);
+
+sub visit_object {
+	my ( $v, $obj ) = @_;
+
+	my $class = ref $obj;
+
+	my $meta = $v->load_classes
+		? Class::MOP::load_class($class)
+		: Class::MOP::get_metaclass_by_name($class);
+
+	if ( ref $meta ) {
+		return $v->visit_object_with_meta($obj, $meta);
+	} else {
+		return $v->visit_ref($obj);
+	}
+}
+
+sub visit_object_with_meta {
+	my ( $v, $obj, $meta ) = @_;
+
+	my $instance = $meta->get_meta_instance->create_instance;
+
+	$v->_register_mapping( $obj => $instance );
+
+	my $args = $v->prepare_args( $obj );
+
+	$meta->new_object( %$args, __INSTANCE__ => $instance );
+
+	$instance->BUILDALL($args) if $instance->can("BUILDALL");
+
+	return $instance;
+}
+
+sub prepare_args {
+	my ( $v, $obj ) = @_;
+
+	my %args;
+	@args{keys %$obj} = $v->visit(values %$obj);
+
+	return \%args;
+}
+
+__PACKAGE__->meta->make_immutable;
+
+__PACKAGE__
+
+__END__
+
+=pod
+
+=head1 NAME
+
+MooseX::Blessed::Reconstruct - A L<Data::Visitor> for creating Moose objects
+from blessed placeholders
+
+=head1 SYNOPSIS
+
+	use MooseX::Blessed::Reconstruct;
+
+
+	my $obj = bless( {
+		init_arg_foo => "Blah",
+		arf => "yay",
+	}, "Foo" );
+
+	my $proper = MooseX::Blessed::Reconstruct->new->visit($obj);
+
+
+
+	# equivalent to:
+
+	my $proper = Foo->meta->new_object(%$obj);
+	$proper->BUILDALL({%$obj});
+
+	# but recursive (and works with shared references)
+
+=head1 DESCRIPTION
+
+The purpose of this module is to "fix up" blessed data into a real Moose
+object.
+
+This is used internally by L<MooseX::YAML> but has no implementation details
+having to do with L<YAML> itself.
+
+=head1 METHODS
+
+See L<Data::Visitor>
+
+=over 4
+
+=item visit_object $object
+
+Calls L<Class::MOP/load_class> on the C<ref> of $object.
+
+If there's a metaclass, calls C<visit_object_with_meta>, otherwise C<visit_ref>
+is used to walk the object brutishly.
+
+Returns a deep clone of the input structure with all the L<Moose> objects
+reconstructed "properly".
+
+=item visit_object_with_meta $obj, $meta
+
+Uses the metaclass C<$meta> to create a new instance, registers the instance
+with L<Data::Visitor>'s cycle tracking, and then inflates it using
+L<Moose::Meta::Class/new_object>.
+
+After the object is built, C<BUILDALL> is called if the object implements it.
+
+=item prepare_args $obj
+
+Collapses $obj into key value pairs to be used as init args to
+L<Moose::Meta::Class/new_object>.
+
+=back
+
+=head1 VERSION CONTROL
+
+This module is maintained using Darcs. You can get the latest version from
+L<http://nothingmuch.woobling.org/code>, and use C<darcs send> to commit
+changes.
+
+=head1 AUTHOR
+
+Jonathan Rockway
+
+Yuval Kogman E<lt>nothingmuch at woobling.orgE<gt>
+
+=head1 COPYRIGHT
+
+	Copyright (c) 2008 Infinity Interactive, Yuval Kogman. All rights
+	reserved This program is free software; you can redistribute
+	it and/or modify it under the same terms as Perl itself.
+
+=cut

Added: branches/upstream/libmoosex-blessed-reconstruct-perl/current/t/basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-blessed-reconstruct-perl/current/t/basic.t?rev=37117&op=file
==============================================================================
--- branches/upstream/libmoosex-blessed-reconstruct-perl/current/t/basic.t (added)
+++ branches/upstream/libmoosex-blessed-reconstruct-perl/current/t/basic.t Mon Jun  1 08:51:04 2009
@@ -1,0 +1,83 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More 'no_plan';
+use Scalar::Util qw(refaddr);
+
+use ok 'MooseX::Blessed::Reconstruct';
+
+{
+	# convince Perl these classes are loaded
+	{ package Some::Foo; sub foo {}; package Some::Bar; sub bar {} }
+
+	my $v = MooseX::Blessed::Reconstruct->new;
+
+	isa_ok( $v, "MooseX::Blessed::Reconstruct" );
+
+	my $obj = bless({
+		oh => "hai",
+		bar => bless({
+			name => "Hello",
+		}, "Some::Bar"),
+	}, "Some::Foo");
+
+	$obj->{bar2} = $obj->{bar};
+
+	my $fixed = $v->visit($obj);
+
+	isa_ok( $fixed, "Some::Foo" );
+	isa_ok( $fixed->{bar}, "Some::Bar" );
+	isa_ok( $fixed->{bar2}, "Some::Bar" );
+	is( refaddr($fixed->{bar}), refaddr($fixed->{bar2}), "refaddr for shared ref" );
+	is( $fixed->{oh}, "hai", "simple value" );
+}
+
+{
+	{
+		package A::Nonmoose::Class; # not to be confused with an anonymous class!
+
+		sub new { bless $_[1], $_[0] }
+
+		sub name { $_[0]{name} }
+
+		package A::Moose::Class;
+		use Moose;
+
+		has string => ( is => 'ro', isa => 'Str', required => 1 );
+		has _      => ( is => 'ro', isa => 'Str', required => 1, init_arg => 'foo' );
+		has ignore => ( is => 'ro', isa => 'Str', default => 'ok', init_arg => undef );
+		has other  => ( is => 'ro', isa => 'A::Nonmoose::Class' );
+		has moose  => ( is => 'ro', isa => 'Str', default => 'hi' );
+		has extra  => ( is => 'rw' );
+
+		sub BUILD { shift->extra("yatta") }
+	}
+
+	my $obj = bless( {
+		string => 'test',
+		foo    => 'bar',
+		other  => bless({ name => "Yuval"}, "A::Nonmoose::Class"),
+	}, 'A::Moose::Class');
+
+	isnt $obj->{moose}, 'hi', 'default not yet created';
+	isnt $obj->{extra}, 'extra', 'BUILD not called';
+
+	my $fixed = MooseX::Blessed::Reconstruct->new->visit($obj);
+
+	isnt( refaddr($fixed), refaddr($obj), "new object" );
+
+	isa_ok $fixed, 'A::Moose::Class';
+	isa_ok $fixed->other, 'A::Nonmoose::Class';
+
+	is $fixed->string, 'test', 'simple data';
+	is $fixed->other->name, 'Yuval', 'nested object data';
+	is $fixed->_, 'bar', 'init_arg value works';
+	is $fixed->moose, 'hi', '"default" worked';
+	is $fixed->ignore, 'ok', 'no init-arg';
+	is $fixed->extra, 'yatta', 'BUILD called';
+
+	isnt $obj->{moose}, 'hi', 'proto was not destroyed';
+	isnt $obj->{extra}, 'extra', 'proto was not destroyed';
+}




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