Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
677 changes: 677 additions & 0 deletions dev/modules/yaml_any_fixes.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main/java/org/perlonjava/core/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class Configuration {
* Automatically populated by Gradle/Maven during build.
* DO NOT EDIT MANUALLY - this value is replaced at build time.
*/
public static final String gitCommitId = "25b6fa935";
public static final String gitCommitId = "785f794f7";

/**
* Git commit date of the build (ISO format: YYYY-MM-DD).
Expand All @@ -48,7 +48,7 @@ public final class Configuration {
* Parsed by App::perlbrew and other tools via: perl -V | grep "Compiled at"
* DO NOT EDIT MANUALLY - this value is replaced at build time.
*/
public static final String buildTimestamp = "Apr 28 2026 18:03:29";
public static final String buildTimestamp = "Apr 28 2026 19:44:47";

// Prevent instantiation
private Configuration() {
Expand Down
121 changes: 111 additions & 10 deletions src/main/perl/lib/YAML.pm
Original file line number Diff line number Diff line change
@@ -1,16 +1,117 @@
package YAML;
our $VERSION = '1.31';

use strict;
use warnings;
use YAML::PP qw(Load Dump LoadFile DumpFile);
use Exporter 'import';
use YAML::Mo;

our @EXPORT = qw(Load Dump);
our @EXPORT_OK = qw(LoadFile DumpFile freeze thaw);
our $VERSION = '1.31'; # Match CPAN YAML version; we wrap YAML::PP
use Exporter;
push @YAML::ISA, 'Exporter';
our @EXPORT = qw{ Dump Load };
our @EXPORT_OK = qw{ freeze thaw DumpFile LoadFile Bless Blessed };
our (
$UseCode, $DumpCode, $LoadCode,
$SpecVersion,
$UseHeader, $UseVersion, $UseBlock, $UseFold, $UseAliases,
$Indent, $SortKeys, $Preserve,
$AnchorPrefix, $CompressSeries, $InlineSeries, $Purity,
$Stringify, $Numify, $LoadBlessed, $QuoteNumericStrings,
$DumperClass, $LoaderClass
);

# Storable-compatible aliases used by POE::Filter::Reference
*freeze = \&Dump;
*thaw = \&Load;
use YAML::Node; # XXX This is a temp fix for Module::Build
use Scalar::Util qw/ openhandle /;

# XXX This VALUE nonsense needs to go.
use constant VALUE => "\x07YAML\x07VALUE\x07";

# YAML Object Properties
has dumper_class => default => sub {'YAML::Dumper'};
has loader_class => default => sub {'YAML::Loader'};
has dumper_object => default => sub {$_[0]->init_action_object("dumper")};
has loader_object => default => sub {$_[0]->init_action_object("loader")};

sub Dump {
my $yaml = YAML->new;
$yaml->dumper_class($YAML::DumperClass)
if $YAML::DumperClass;
return $yaml->dumper_object->dump(@_);
}

sub Load {
my $yaml = YAML->new;
$yaml->loader_class($YAML::LoaderClass)
if $YAML::LoaderClass;
return $yaml->loader_object->load(@_);
}

{
no warnings 'once';
# freeze/thaw is the API for Storable string serialization. Some
# modules make use of serializing packages on if they use freeze/thaw.
*freeze = \ &Dump;
*thaw = \ &Load;
}

sub DumpFile {
my $OUT;
my $filename = shift;
if (openhandle $filename) {
$OUT = $filename;
}
else {
my $mode = '>';
if ($filename =~ /^\s*(>{1,2})\s*(.*)$/) {
($mode, $filename) = ($1, $2);
}
open $OUT, $mode, $filename
or YAML::Mo::Object->die('YAML_DUMP_ERR_FILE_OUTPUT', $filename, "$!");
}
binmode $OUT, ':utf8'; # if $Config{useperlio} eq 'define';
local $/ = "\n"; # reset special to "sane"
print $OUT Dump(@_);
unless (ref $filename eq 'GLOB') {
close $OUT
or do {
my $errsav = $!;
YAML::Mo::Object->die('YAML_DUMP_ERR_FILE_OUTPUT_CLOSE', $filename, $errsav);
}
}
}

sub LoadFile {
my $IN;
my $filename = shift;
if (openhandle $filename) {
$IN = $filename;
}
else {
open $IN, '<', $filename
or YAML::Mo::Object->die('YAML_LOAD_ERR_FILE_INPUT', $filename, "$!");
}
binmode $IN, ':utf8'; # if $Config{useperlio} eq 'define';
return Load(do { local $/; <$IN> });
}

sub init_action_object {
my $self = shift;
my $object_class = (shift) . '_class';
my $module_name = $self->$object_class;
eval "require $module_name";
$self->die("Error in require $module_name - $@")
if $@ and "$@" !~ /Can't locate/;
my $object = $self->$object_class->new;
$object->set_global_options;
return $object;
}

my $global = {};
sub Bless {
require YAML::Dumper::Base;
YAML::Dumper::Base::bless($global, @_)
}
sub Blessed {
require YAML::Dumper::Base;
YAML::Dumper::Base::blessed($global, @_)
}
sub global_object { $global }

1;
123 changes: 123 additions & 0 deletions src/main/perl/lib/YAML/Any.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
use strict; use warnings;
package YAML::Any;
our $VERSION = '1.31';

use Exporter ();

@YAML::Any::ISA = 'Exporter';
@YAML::Any::EXPORT = qw(Dump Load);
@YAML::Any::EXPORT_OK = qw(DumpFile LoadFile);

my @dump_options = qw(
UseCode
DumpCode
SpecVersion
Indent
UseHeader
UseVersion
SortKeys
AnchorPrefix
UseBlock
UseFold
CompressSeries
InlineSeries
UseAliases
Purity
Stringify
);

my @load_options = qw(
UseCode
LoadCode
Preserve
);

my @implementations = qw(
YAML::XS
YAML::Syck
YAML::Old
YAML
YAML::Tiny
);

sub import {
__PACKAGE__->implementation;
goto &Exporter::import;
}

sub Dump {
no strict 'refs';
no warnings 'once';
my $implementation = __PACKAGE__->implementation;
for my $option (@dump_options) {
my $var = "$implementation\::$option";
my $value = $$var;
local $$var;
$$var = defined $value ? $value : ${"YAML::$option"};
}
return &{"$implementation\::Dump"}(@_);
}

sub DumpFile {
no strict 'refs';
no warnings 'once';
my $implementation = __PACKAGE__->implementation;
for my $option (@dump_options) {
my $var = "$implementation\::$option";
my $value = $$var;
local $$var;
$$var = defined $value ? $value : ${"YAML::$option"};
}
return &{"$implementation\::DumpFile"}(@_);
}

sub Load {
no strict 'refs';
no warnings 'once';
my $implementation = __PACKAGE__->implementation;
for my $option (@load_options) {
my $var = "$implementation\::$option";
my $value = $$var;
local $$var;
$$var = defined $value ? $value : ${"YAML::$option"};
}
return &{"$implementation\::Load"}(@_);
}

sub LoadFile {
no strict 'refs';
no warnings 'once';
my $implementation = __PACKAGE__->implementation;
for my $option (@load_options) {
my $var = "$implementation\::$option";
my $value = $$var;
local $$var;
$$var = defined $value ? $value : ${"YAML::$option"};
}
return &{"$implementation\::LoadFile"}(@_);
}

sub order {
return @YAML::Any::_TEST_ORDER
if @YAML::Any::_TEST_ORDER;
return @implementations;
}

sub implementation {
my @order = __PACKAGE__->order;
for my $module (@order) {
my $path = $module;
$path =~ s/::/\//g;
$path .= '.pm';
return $module if exists $INC{$path};
eval "require $module; 1" and return $module;
}
croak("YAML::Any couldn't find any of these YAML implementations: @order");
}

sub croak {
require Carp;
Carp::croak(@_);
}

1;
Loading
Loading