Skip to content

Commit

Permalink
Add more tests. Address issue w/ perlbrew 5.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nebulous committed Feb 20, 2015
1 parent 074ba56 commit 0a76259
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
13 changes: 9 additions & 4 deletions lib/XML/Simple/Minded.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ has _xml => (is=>'rw', default=>sub{''});
has _struc => (is=>'rw', default=>sub{{}});
has _root => (is=>'rw');
has _parent => (is=>'rw');
has _depth => (is=>'ro', default=>0);

sub FOREIGNBUILDARGS {
return (force_array=>1, keep_root=>1, key_attr=>[]);
Expand All @@ -34,10 +35,13 @@ sub BUILDARGS {
sub BUILD {
my $self = shift;
$self->_struc($self->XMLin($self->_xml)) if $self->_xml;
#my $clone = { %{$self->_struc||{} } };
$self->_struc(Hash::AsObject->new($self->_struc));
}

sub DESTROY {
my $self = shift;
}

sub TO_JSON {
my $self = shift;
return $self->_struc();
Expand Down Expand Up @@ -93,20 +97,21 @@ sub AUTOLOAD {
my $self = shift;
my $search = $AUTOLOAD;
$search =~ s/XML::Simple::Minded:://;
die 'Suspicious recursion' if $self->_depth>99;

sub haso {
my ($in, $parent) = @_;
my $ref = ref($in);

if ($ref eq 'ARRAY') {
return &haso($in->[0]) if scalar(@$in) == 1;
return &haso($in->[0], $parent) if scalar(@$in) == 1;
foreach my $e (@$in) {
$e = &haso($e, $parent);
}
return $in;
}
if ($ref eq 'HASH' or $ref eq 'Hash::AsObject') {
return XML::Simple::Minded->new(_struc=>$in, _parent=>$parent);
return XML::Simple::Minded->new(_struc=>$in, _parent=>$parent, _depth=>$parent ? ($parent->_depth+1) : 0);
}
return $in;
};
Expand All @@ -121,7 +126,7 @@ sub AUTOLOAD {
}
my $res = $self->_struc->$search();
if (!defined($res)) {
return XML::Simple::Minded->new(_root=>$search, _parent=>$self);
return XML::Simple::Minded->new(_root=>$search, _parent=>$self, _depth=>99);
}
return &haso($res,$self);
}
Expand Down
10 changes: 7 additions & 3 deletions t/01-xml-simple-minded.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ BEGIN {
use_ok('XML::Simple::Minded');
}

my $xml = XML::Simple::Minded->new("$FindBin::Bin/systems17.raw");
my $xml = XML::Simple::Minded->new("<this that=\"option\">valueforthis</this>");
isa_ok($xml, 'XML::Simple::Minded');
is($xml->this->content,'valueforthis', 'contents');
is($xml->this->that,'option','attributes');
$xml = undef;

is($xml->system->config->mode,'auto');
$xml = XML::Simple::Minded->new("$FindBin::Bin/systems17.raw");
is($xml->system->config->mode,'auto','XML parses');

$xml->system->config->testitem(['test value']);
is($xml->system->config->testitem,'test value');
is($xml->system->config->testitem,'test value','New values added');

my $xml_string = $xml."";
ok($xml_string =~ m/^<\?xml/,'xml stringifies definition');
Expand Down
2 changes: 1 addition & 1 deletion t/system-post.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Test::More;
use Test::More tests=>9;
use Test::Mojo;

# Include application
Expand Down

0 comments on commit 0a76259

Please sign in to comment.