MooseX-YAML-0.05/0000755000175000017500000000000013620340452012057 5ustar tinatinaMooseX-YAML-0.05/Makefile.PL0000644000175000017500000000077113620340117014034 0ustar tinatina#!/usr/bin/perl -w use strict; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'MooseX::YAML', ABSTRACT => 'DWIM loading of Moose objects from YAML', AUTHOR => 'Yuval Kogman ', LICENSE => 'perl', VERSION_FROM => 'lib/MooseX/YAML.pm', INSTALLDIRS => 'site', PL_FILES => { }, PREREQ_PM => { 'Test::use::ok' => 0, 'YAML' => 0, 'MooseX::Blessed::Reconstruct' => '0.03', 'Sub::Exporter' => '0.982', 'namespace::clean' => 0, }, ); MooseX-YAML-0.05/t/0000755000175000017500000000000013620340452012322 5ustar tinatinaMooseX-YAML-0.05/t/fq.t0000644000175000017500000000100011131764005013103 0ustar tinatina#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; require_ok 'MooseX::YAML'; { package Foo; use Moose; has oh => ( is => "ro", isa => "Str" ); has blah => ( is => "ro", default => 3 ); has extra => ( is => "rw" ); sub BUILD { shift->extra("yatta") } } my $yml = <oh, "hai", "simple attr" ); is( $obj->blah, 3, "default" ); is( $obj->extra, "yatta", "BUILD" ); } MooseX-YAML-0.05/t/basic.t0000644000175000017500000000257011131764005013573 0ustar tinatina#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; use ok 'MooseX::YAML' => qw(Load); { package Foo; use Moose; has oh => ( is => "ro", isa => "Str" ); has blah => ( is => "ro", default => 3 ); has extra => ( is => "rw" ); sub BUILD { shift->extra("yatta") } } my $yml = <oh, "hai", "simple attr" ); is( $obj->blah, 3, "default" ); is( $obj->extra, "yatta", "BUILD" ); } SKIP: { skip "YAML::XS required", 4 unless eval { require YAML::XS }; package XS_test; MooseX::YAML->import(qw(Load -xs)); my $obj = Load($yml); ::isa_ok( $obj, "Foo" ); ::is( $obj->oh, "hai", "simple attr" ); ::is( $obj->blah, 3, "default" ); ::is( $obj->extra, "yatta", "BUILD" ); } SKIP: { skip "YAML::Syck required", 4 unless eval { require YAML::Syck }; package Syck_test; MooseX::YAML->import(qw(Load -syck)); my $obj = Load($yml); ::isa_ok( $obj, "Foo" ); ::is( $obj->oh, "hai", "simple attr" ); ::is( $obj->blah, 3, "default" ); ::is( $obj->extra, "yatta", "BUILD" ); } SKIP: { skip "YAML required", 4 unless eval { require YAML }; package PP_test; MooseX::YAML->import(qw(Load -pp)); my $obj = Load($yml); ::isa_ok( $obj, "Foo" ); ::is( $obj->oh, "hai", "simple attr" ); ::is( $obj->blah, 3, "default" ); ::is( $obj->extra, "yatta", "BUILD" ); } MooseX-YAML-0.05/lib/0000755000175000017500000000000013620340452012625 5ustar tinatinaMooseX-YAML-0.05/lib/MooseX/0000755000175000017500000000000013620340452014037 5ustar tinatinaMooseX-YAML-0.05/lib/MooseX/YAML.pm0000644000175000017500000000651513620340216015144 0ustar tinatina#!/usr/bin/perl package MooseX::YAML; use strict; use warnings; our $VERSION = "0.05"; use Carp qw(croak); use MooseX::Blessed::Reconstruct; my $v; sub fixup { ($v ||= MooseX::Blessed::Reconstruct->new)->visit(@_) } use namespace::clean; use Sub::Exporter -setup => { exports => [qw(Load LoadFile)], collectors => [ "-xs", "-syck", "-pp" ], generator => sub { foreach my $export ( @_ ) { my $r = $export->{class}->_resolve($export->{name}, $export->{col}); return sub { fixup( $r->(@_) ) }; } }, }; sub _resolve { my ( $class, $routine, $flags ) = @_; if ( keys %$flags ) { croak "Can't use more than one of -xs, -syck or -pp" if keys %$flags > 1; if ( exists $flags->{-xs} ) { require YAML::XS; my $sub = YAML::XS->can($routine); return sub { local $YAML::XS::LoadBlessed = 1; $sub->(@_); }; } elsif ( exists $flags->{-syck} ) { require YAML::Syck; my $sub = YAML::Syck->can($routine); return sub { local $YAML::Syck::LoadBlessed = 1; $sub->(@_); }; } else { require YAML; my $sub = YAML->can($routine); return sub { local $YAML::LoadBlessed = 1; $sub->(@_); }; } } else { my $drv = ( do { local $@; eval { require YAML::XS; "YAML::XS" } } or require YAML && "YAML" ); my $sub = $drv->can($routine) || croak "Can't find a provided for $routine (fallback is $drv)"; return sub { local $YAML::LoadBlessed = 1; local $YAML::XS::LoadBlessed = 1; $sub->(@_); }; } } my $load; sub Load { $load ||= __PACKAGE__->_resolve("Load"); fixup( $load->(@_) ); } my $loadfile; sub LoadFile { $loadfile ||= __PACKAGE__->_resolve("LoadFile"); fixup( $loadfile->(@_) ); } __PACKAGE__ __END__ =pod =head1 NAME MooseX::YAML - DWIM loading of Moose objects from YAML =head1 SYNOPSIS # given some class: package My::Module; use Moose; has package => ( is => "ro", init_arg => "name", ); has version => ( is => "rw", init_arg => undef, ); sub BUILD { shift->version(3) } # load an object like so: use MooseX::YAML qw(Load -xs); my $obj = Load(<<'YAML'); --- !My::Module # this syntax requires YAML::XS name: "MooseX::YAML" YAML $obj->package; # "MooseX::YAML" $obj->version; # 3, BUILD was called =head1 DESCRIPTION This module provides DWIM loading of L based objects from YAML documents. Any hashes blessed into a L class will be replaced with a properly constructed instance (respecting init args, C, and the meta instance type). This is similar to L in that certain nodes in the loaded YAML documented are treated specially. =head1 EXPORTS All exports are setup by L using currying. C<-xs>, C<-syck> or C<-pp> can be specified to specify L, L or L on a per import basis. If no driver is explicitly chosen L will be tried first, falling back to L. =over 4 =item Load =item LoadFile =back =head1 VERSION CONTROL This module is maintained using Darcs. You can get the latest version from L, and use C to commit changes. =head1 AUTHOR Yuval Kogman Enothingmuch@woobling.orgE =head1 COPYRIGHT Copyright (c) 2008 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 MooseX-YAML-0.05/MANIFEST.SKIP0000644000175000017500000000116213620060763013761 0ustar tinatina# 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)$ ^local/ ^MYMETA ^.gitignore MooseX-YAML-0.05/Changes0000644000175000017500000000071013620340304013344 0ustar tinatina0.05 2020-02-10 21:44:50+01:00 - Set $LoadBlessed to 1 (fixes https://rt.cpan.org/Ticket/Display.html?id=131714) YAML.pm, YAML::Syck and YAML::XS changed their default to 0 0.04 - specify explicit version dependency on MooseX::Blessed::Reconstruct 0.03 - Sub::Exporter provides undef for the flags, check for existence instead 0.02 - Add support for fully qualified functions (i.e. MooseX::YAML::Load) 0.01 - Initial release MooseX-YAML-0.05/MANIFEST0000644000175000017500000000035113620340452013207 0ustar tinatinaChanges lib/MooseX/YAML.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.yml Module meta-data (added by MakeMaker) t/basic.t t/fq.t META.json Module JSON meta-data (added by MakeMaker) MooseX-YAML-0.05/META.json0000644000175000017500000000212413620340452013477 0ustar tinatina{ "abstract" : "DWIM loading of Moose objects from YAML", "author" : [ "Yuval Kogman " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.3, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "MooseX-YAML", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "MooseX::Blessed::Reconstruct" : "0.03", "Sub::Exporter" : "0.982", "Test::use::ok" : "0", "YAML" : "0", "namespace::clean" : "0" } } }, "release_status" : "stable", "version" : "0.05", "x_serialization_backend" : "JSON::PP version 2.97001" } MooseX-YAML-0.05/META.yml0000644000175000017500000000124313620340452013330 0ustar tinatina--- abstract: 'DWIM loading of Moose objects from YAML' author: - 'Yuval Kogman ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.3, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: MooseX-YAML no_index: directory: - t - inc requires: MooseX::Blessed::Reconstruct: '0.03' Sub::Exporter: '0.982' Test::use::ok: '0' YAML: '0' namespace::clean: '0' version: '0.05' x_serialization_backend: 'CPAN::Meta::YAML version 0.018'