Skip to content

Instantly share code, notes, and snippets.

Created June 2, 2012 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2858050 to your computer and use it in GitHub Desktop.
Save anonymous/2858050 to your computer and use it in GitHub Desktop.
use Mojolicious::Lite;
use Mojo::UserAgent;
use Modern::Perl;
get '/' => sub {
# get this to render the hello tempalte
my $ua = Mojo::UserAgent->new;
my $self = shift;
my $base_url ='http://api.powerhousemuseum.com/api/v1/category/xml/';
my $api_key = '8fbb61ea34d6f5d';
my $base_rest_url ="$base_url?&api_key=$api_key";
my @names =$ua->get("$base_rest_url")->res->dom->find('name')->map( sub { $_->text } );
$self->stash( name => @names );
$self->render('hello');
};
#start the application
app->start;
## the rest of the file will be a template for markup
## Hello template:
__DATA__
@@ hello.html.ep
% for my $name (@$names) {
<li>
$name
</li>
% }
</ul>
<br>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment