package BAST::C::Default;

use base qw/Catalyst::Base/;

sub bootstrap : Path('/bootstrap') {
  my ($self, $c) = @_;
  $c->serve_static;
}

sub lang_perl : Path('/lang/perl') {
  my ($self, $c) = @_;
  my $sub = eval "sub { ".$c->req->document->textContent." };";
  die $@ if $@;
  $c->res->body($sub->($self, $c));
}

sub literal : Path('/literal') {
  my ($self, $c) = @_;
  my ($child) = $c->current->findnodes('*');
  my $doc = XML::LibXML::Document->createDocument;
  $doc->setDocumentElement($child->cloneNode( 1 )); # 1 = deep
  $c->res->document($doc);
}

sub primitive_exec : Path('/primitive-exec') {
  my ($self, $c) = @_;
  my $trans = BAST::Frame->create();
  $c->uri_redispatch($c->req, $trans);
  $c->primitive_execute($trans);
}

sub null : Path('/null') { }

1;
