/usr/share/perl5/MooseX/YAML.pm is in libmoosex-yaml-perl 0.04-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | #!/usr/bin/perl
package MooseX::YAML;
use strict;
use warnings;
our $VERSION = "0.04";
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;
return YAML::XS->can($routine);
} elsif ( exists $flags->{-syck} ) {
require YAML::Syck;
return YAML::Syck->can($routine);
} else {
require YAML;
return YAML->can($routine);
}
} else {
my $drv = (
do { local $@; eval { require YAML::XS; "YAML::XS" } }
or
require YAML && "YAML"
);
return $drv->can($routine) || croak "Can't find a provided for $routine (fallback is $drv)";
}
}
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<Moose> based objects from YAML
documents.
Any hashes blessed into a L<Moose> class will be replaced with a properly
constructed instance (respecting init args, C<BUILDALL>, and the meta instance
type).
This is similar to L<YAML::Active> in that certain nodes in the loaded YAML
documented are treated specially.
=head1 EXPORTS
All exports are setup by L<Sub::Exporter> using currying.
C<-xs>, C<-syck> or C<-pp> can be specified to specify L<YAML::XS>,
L<YAML::Syck> or L<YAML> on a per import basis.
If no driver is explicitly chosen L<YAML::XS> will be tried first, falling back
to L<YAML>.
=over 4
=item Load
=item LoadFile
=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
Yuval Kogman E<lt>nothingmuch@woobling.orgE<gt>
=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
|