package Wiki::Score::HS;

use 5.006;
use strict;
use warnings;

=head1 NAME

Wiki::Score::HS - The great new Wiki::Score::HS!

=head1 VERSION

Version 0.01

=cut

our $VERSION = '0.01';


=head1 SYNOPSIS

Quick summary of what the module does.

Perhaps a little code snippet.

    use Wiki::Score::HS;

    my $hs = Wiki::Score::HS->new();
    my $result = $hs->eval('prjAttrs "Demetrio"');
    ...

=head1 EXPORT

A list of functions that can be exported.  You can delete this section
if you don't export anything, such as for a purely object-oriented module.

=head1 SUBROUTINES/METHODS

=head2 new

=cut

sub new {
	my ($class) = @_;
   my $self = bless({}, $class);

	$self->{prefix} = '/usr/bin/ghc -e';
	$self->{file} = 'wikiscore.hs';

   return $self;
}

=head2 eval

=cut

sub eval {
	my ($self, $expr) = @_;

	my $command = sprintf "%s '%s' %s", $self->{prefix}, $expr, $self->{file};
	my $haskell = `$command`;
	my $perl = $haskell;

	my $ref;
	if ($haskell =~ m/^\s*\[/ and $haskell =~ m/\]\s*$/) {
		$ref = 'ARRAY';
	}
	if ($haskell =~ m/^\s*\w+\s*\{/ and $haskell =~ m/\}\s*$/) {
		$ref = 'HASH';
	}

	#if ($ref eq 'HASH') {
		#$perl =~ s/^(\w+)/$1 =>/;
	#}

	# set attributes to hash
	$perl =~ s/A\s*{\s*name\s*=\s*"(.*?)",\s*value\s*=\s*"(.*?)"\s*}/{ $1 => "$2" }/g;
	$perl =~ s/\[\w+\s\{/[ {/;
	$perl =~ s/(\w+)\s*(\{|\[)/$1 => $2/g;
	$perl =~ s/ = / => /g;

	#return eval $perl;
	return $perl;
}

=head1 AUTHOR

Nuno Carvalho, C<< <smash at cpan.org> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-wiki-score-hs at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Wiki-Score-HS>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.




=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Wiki::Score::HS


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker (report bugs here)

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Wiki-Score-HS>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/Wiki-Score-HS>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/Wiki-Score-HS>

=item * Search CPAN

L<http://search.cpan.org/dist/Wiki-Score-HS/>

=back


=head1 ACKNOWLEDGEMENTS


=head1 LICENSE AND COPYRIGHT

Copyright 2012 Nuno Carvalho.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.


=cut

1; # End of Wiki::Score::HS
