From: Stevan Little Date: Tue, 3 Jul 2007 21:03:48 +0000 (+0000) Subject: adding better tests for utils X-Git-Tag: 0_04~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=021c860a88571df9ead937f3bfd199e3cd6e6404;p=gitmo%2FMooseX-Storage.git adding better tests for utils --- diff --git a/Changes b/Changes index f6dcbae..06e5da7 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,12 @@ Revision history for MooseX-Storage +0.04 + * MooseX::Storage::Util + - made this more robust when it tries + to use YAML and JSON loaders and fails + to find one + - fixed tests to reflect this + 0.03 Wed. June 27, 2007 * MooseX::Storage::Util - this is a collection of useful tools diff --git a/README b/README index d8e92b9..e1ea222 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -MooseX-Storage version 0.03 +MooseX-Storage version 0.04 INSTALLATION diff --git a/lib/MooseX/Storage.pm b/lib/MooseX/Storage.pm index 192c6ee..bcd2761 100644 --- a/lib/MooseX/Storage.pm +++ b/lib/MooseX/Storage.pm @@ -4,7 +4,7 @@ use Moose qw(confess); use MooseX::Storage::Meta::Attribute::DoNotSerialize; -our $VERSION = '0.03'; +our $VERSION = '0.04'; our $AUTHORITY = 'cpan:STEVAN'; sub import { diff --git a/lib/MooseX/Storage/Util.pm b/lib/MooseX/Storage/Util.pm index e13ea97..e0ddcb7 100644 --- a/lib/MooseX/Storage/Util.pm +++ b/lib/MooseX/Storage/Util.pm @@ -3,7 +3,7 @@ use Moose qw(confess blessed); use MooseX::Storage::Engine (); -our $VERSION = '0.01'; +our $VERSION = '0.02'; our $AUTHORITY = 'cpan:STEVAN'; sub peek { @@ -32,7 +32,8 @@ sub _inflate_json { my ($class, $json) = @_; require JSON::Any; - JSON::Any->import; + eval { JSON::Any->import }; + confess "Could not load JSON module because : $@" if $@; my $data = eval { JSON::Any->jsonToObj($json) }; if ($@) { @@ -46,7 +47,9 @@ sub _inflate_yaml { my ($class, $yaml) = @_; require Best; - Best->import([[ qw[YAML::Syck YAML] ]]); + eval { Best->import([[ qw[YAML::Syck YAML] ]]) }; + confess "Could not load YAML module because : $@" if $@; + my $inflater = Best->which('YAML::Syck')->can('Load'); diff --git a/t/040_basic_utils.t b/t/040_basic_utils.t index 802e841..3e1690c 100644 --- a/t/040_basic_utils.t +++ b/t/040_basic_utils.t @@ -56,19 +56,31 @@ object: string: foo }; -is( -'Foo', -MooseX::Storage::Util->peek($packed), -'... got the right class name from the packed item'); +is('Foo', MooseX::Storage::Util->peek($packed), + '... got the right class name from the packed item'); -is( -'Foo', -MooseX::Storage::Util->peek($json => ('format' => 'JSON')), -'... got the right class name from the json item'); +SKIP: { + my $classname = eval { + MooseX::Storage::Util->peek($json => ('format' => 'JSON')) + }; + if ($@ =~ /^Could not load JSON module because/) { + skip "No JSON module found", 1; + } -is( -'Foo', -MooseX::Storage::Util->peek($yaml => ('format' => 'YAML')), -'... got the right class name from the yaml item'); + is('Foo', $classname, + '... got the right class name from the json item'); +} + +SKIP: { + my $classname = eval { + MooseX::Storage::Util->peek($yaml => ('format' => 'YAML')) + }; + if ($@ =~ /^Could not load YAML module because/) { + skip "No YAML module found", 1; + } + + is('Foo', $classname, + '... got the right class name from the yaml item'); +}