Created
August 9, 2012 18:44
-
-
Save aubreyja/3307022 to your computer and use it in GitHub Desktop.
AskSage.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#For command line: | |
use AskSage; | |
use strict; | |
use warnings; | |
my $python = $ARGV[0]; | |
my $sager = AskSage -> new(); | |
my $response = $sager -> get_response($python); | |
print $response."\n"; | |
#For pg/macros/: | |
sub _ask_sage_init {}; | |
sub ask_sage { | |
my $python = shift; | |
my $sager = AskSage -> new(); | |
return $sager -> get_response($python); | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use HTTP::Tiny; | |
use JSON; | |
package AskSage; | |
sub new { | |
my $class = shift; | |
my $self = { | |
url => 'http://aleph.sagemath.org/service', | |
req => HTTP::Tiny->new(), | |
}; | |
bless $self, $class; | |
return $self; | |
} | |
sub get_response { | |
my ($self,$python) = @_; | |
my $url = $self -> {url}; | |
my $req = $self -> {req}; | |
my $json = $self -> {json}; | |
my $response = $req->post_form($url,{code=>$python}); | |
my $json = $response -> {content}; | |
my $hashref = JSON::decode_json($json); | |
return $hashref->{stdout}; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment