Added Parson module to parse json.
authorJeremiah Foster <jeremiah@test.maemo.org>
Thu, 22 Oct 2009 23:52:04 +0000 (02:52 +0300)
committerJeremiah Foster <jeremiah@test.maemo.org>
Thu, 22 Oct 2009 23:52:04 +0000 (02:52 +0300)
Parson.pm [new file with mode: 0755]
minimae-2.0
t/parson [new file with mode: 0644]

diff --git a/Parson.pm b/Parson.pm
new file mode 100755 (executable)
index 0000000..a588f48
--- /dev/null
+++ b/Parson.pm
@@ -0,0 +1,52 @@
+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;
index cfc50ff..6af4525 100755 (executable)
@@ -41,6 +41,12 @@ use Archive::Tar;
 use Perl6::Slurp;
 use RepoUtils;
 use File::Basename;
+use Parson;
+
+# find our tarball
+my $json_object = Parson->new();              # parse json file
+my $dsc = $json_object->parse_json();
+
 
 my $tarball = $ARGV[0];                       # Orignal tarball
 my $repo = RepoUtils->new();
@@ -57,7 +63,7 @@ else {
 }
 $package_name =~ tr/_/-/;                     # translate underscore into dash
 $package_name =~ s/-[\d]$//;                  # trim package version
-$package_name =~ s/-.?maemo.$//;              # trim package version
+$package_name =~ s/-.?maemo.$//;              # trim maemo version
 chdir("lab/");                                # We're in /lab now!
 $tar->extract();                              # extracted tarball now in lab/
 
diff --git a/t/parson b/t/parson
new file mode 100644 (file)
index 0000000..9d22a48
--- /dev/null
+++ b/t/parson
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+# Standard testing of the Parson package which is desinged to 
+# receive a JSON stream and pull out date from it.
+
+use strict;
+use warnings;
+use lib('/home/jeremiah/maemian/');
+use Parson;
+use Test::More tests => 6;
+
+BEGIN { use_ok( 'Parson' ); }
+require_ok( 'Parson' );
+my $json_object = Parson->new();
+isa_ok($json_object, 'Parson');
+like($json_object->file, qr(\/home\/jeremiah\/maemian\/json\.txt), 'Files identical.');
+can_ok($json_object, 'parse_json');
+my $dsc = $json_object->parse_json();
+like($dsc, qr(.*\.dsc$), 'Likely a dsc file');
+print "$dsc\n";