package Parson;

# Copyright (C) Jeremiah C. Foster 2009

=head1 NAME

parson.pl - parse json

=head1 VERSION

This document describes version 0.1

=head1 PURPOSE

Create something readable from a json file

=head1 SYNOPSIS

=cut

use Moose;

has 'file' => ( isa => 'Str', is => 'rw', default => '/home/jeremiah/maemian/json.txt' );

__PACKAGE__->meta->make_immutable;

sub parse_json {
  use JSON;
  use Perl6::Slurp;
  use File::Basename;
  my ($self, $location) = @_;
  my @json = slurp $self->file;
  my $text = decode_json $json[0];

  while( my ($k, $v) = each %$text ) {
    if (ref($v) eq "ARRAY") {
      if ($k eq 'targets') {
	# print map { "ARRAY key: $k, value: @$_\n"  } @$v;
      }
      elsif ($k eq "fnames") {
	my $dsc = "@$v";
	return basename $dsc;
      }
      else {
	# print "ARRAY key: $k, value: @$v.\n";
      }
    }
  }
}


1;
