Skip to content

Commit

Permalink
use JSON::Any instead of ad-hoc JSON/YAML combo
Browse files Browse the repository at this point in the history
  • Loading branch information
jrockway committed Jan 14, 2008
1 parent 8db003e commit 4f3a96e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 34 deletions.
11 changes: 7 additions & 4 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Revision history for Catalyst-Plugin-ConfigLoader-Environment

0.04 14 January 2008
- YAML is causing weird errors; killing it in favor of
making JSON::Any mandatory

0.03 12 January 2008
Fix some problems the CPAN testers uncovered
- Fix some problems the CPAN testers uncovered

0.02 12 January 2008
Add YAML/JSON support from mugwump
- Add YAML/JSON support from mugwump

0.01 9 December 2006
First version, released on an unsuspecting world.

- First version, released on an unsuspecting world.
3 changes: 1 addition & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ license('Perl');
include('ExtUtils::AutoInstall');

requires('Catalyst' => '5.7000');
requires('JSON::Any');
build_requires('Test::More' => 0);
recommends 'JSON';
recommends 'YAML';

auto_install();
WriteAll();
18 changes: 5 additions & 13 deletions lib/Catalyst/Plugin/ConfigLoader/Environment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Catalyst::Plugin::ConfigLoader::Environment;
use warnings;
use strict;
use Catalyst::Utils;
use NEXT;
use JSON::Any;

=head1 NAME
Expand All @@ -12,11 +12,11 @@ application with environment variables.
=head1 VERSION
Version 0.03
Version 0.04
=cut

our $VERSION = '0.03';
our $VERSION = '0.04';

=head1 SYNOPSIS
Expand Down Expand Up @@ -102,8 +102,7 @@ Double colons are converted into double underscores. For
compatibility's sake, support for the 0.01-style use of
bourne-incompatible variable names is retained.
The last one should only be passed JSON. If JSON.pm is not found,
then YAML.pm will be used instead.
The last one should only be passed JSON.
=head1 FUNCTIONS
Expand All @@ -125,14 +124,7 @@ sub setup {
my $item = $3;
my $val = $env{"$var"};
if ($val =~ m{^[\[\{]}) {
eval { require JSON; };
if ($@) {
require YAML;
$val = YAML::Load("$val\n");
}
else {
$val = JSON::jsonToObj($val);
}
$val = JSON::Any->jsonToObj($val);
}
$c->config->{$comp}{$item} = $val;
}
Expand Down
22 changes: 7 additions & 15 deletions t/01-live.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ BEGIN {
$ENV{TESTAPP_bar} = 'bar';
$ENV{TESTAPP_foo_bar_baz} = 'quux';
$ENV{TESTAPP_View::TestView_foo} = "Test View's foo!";
$ENV{TESTAPP_View::TestView_quux} = q%["Test View's quux!"]%;
$ENV{TESTAPP_View::TestView_quux} = q%[1,2,3,"Test View's quux!",{"foo":"bar"}]%;
$ENV{TESTAPP_View__TestView_bar} = "Test View's bar!";

}
Expand All @@ -33,17 +33,9 @@ is($view, "Test View's foo!", 'got View::TestView->foo');
$view = get('/foo/bar');
is($view, "Test View's bar!", 'got View::TestView->bar');

SKIP:{
eval 'use JSON';
if ($@) {
eval 'use YAML';
if ($@) {
skip "no JSON/YAML installed", 1;
}
}

$view = get('/foo/quux');
eval $view;
no warnings 'once';
is_deeply($quux, ["Test View's quux!"], 'got View::TestView->quux');
}
$view = get('/foo/quux');
eval $view;
warn $view;
no warnings 'once';
is_deeply($quux, [1,2,3,"Test View's quux!",{ foo => 'bar'}],
'got View::TestView->quux');

0 comments on commit 4f3a96e

Please sign in to comment.