Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the YAML CPAN distribution.

Report information
The Basics
Id: 20652
Status: new
Priority: 0/
Queue: YAML

People
Owner: Nobody in particular
Requestors: wyant [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Have YAML::Loader load classes on-the-fly?
Download (untitled) / with headers
text/plain 435b
Loading YAML files might be cleaner if the loader would also attempt to load any classes used. The attached unified diff represents one way to do this. The _try_load subroutine actually returns a value, but no use is made of it. Maybe you have something else in the works, though, or some good architectural reason not to do this. But I figured it would not hurt to make the suggestion. Thanks for your time and attention, Tom Wyant
Subject: YAML-Loader.diff
Download YAML-Loader.diff
text/x-diff 1.7k
--- Loader.old Fri Jun 30 17:27:22 2006 +++ Loader.pm Mon Jul 24 15:06:09 2006 @@ -189,6 +189,7 @@ undef $node; $node = \$copy; } + _try_load ($class) if $YAML::Loader::LoadClass; # trw CORE::bless $node, $class; } else { @@ -253,9 +254,11 @@ if ($explicit =~ /^\!perl\/(hash|array|scalar)\:(\w(\w|\:\:)*)?$/) { ($type, $class) = (($1 || ''), ($2 || '')); if (ref $node) { + _try_load ($class) if $YAML::Loader::LoadClass; # trw return CORE::bless $node, $class; } else { + _try_load ($class) if $YAML::Loader::LoadClass; # trw return CORE::bless \$node, $class; } } @@ -282,9 +285,11 @@ } else { if (ref $node) { + _try_load ($class) if $YAML::Loader::LoadClass; # trw return CORE::bless $node, $class; } else { + _try_load ($class) if $YAML::Loader::LoadClass; # trw return CORE::bless \$node, $class; } } @@ -711,6 +716,23 @@ #============================================================================== # Utility subroutines. #============================================================================== + +# Modules we have already tried to load. # trw +my %tried_load; + +# Try to load the module before we bless the object. # trw +sub _try_load { + my $mod = shift; + return $tried_load{$mod} if exists $tried_load{$mod}; + (my $fn = $mod) =~ s|::|/|g; + $fn .= '.pm'; + if ($INC{$fn}) { + $tried_load{$mod} = $fn; + } else { + eval {require $fn}; + $tried_load{$mod} = $@ ? undef : $fn; + } +} # Printable characters for escapes my %unescapes =


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.