use 5.010;
use strict;
use MooseX::Declare;

BEGIN
{
	$WWW::DataWiki::Controller::AUTHORITY = 'cpan:TOBYINK';
	$WWW::DataWiki::Controller::VERSION   = '0.000_01';
}

class WWW::DataWiki::Controller
	extends Catalyst::Controller
{
	use CatalystX::Syntax::Action;

	method _dispatch_by_method ($ctx, $action_stem)
	{
		my $action_name = sprintf('%s_%s', $action_stem, uc $ctx->req->method);
		
		if ($self->can($action_name))
		{
			$ctx->detach(ref $self, $action_name);
		}
		else
		{
			WWW::DataWiki::Exception->throw(405 => 'Method Not Allowed');
		}
	}

	action end
	{
		my $resource = $ctx->stash->{resource};

		my $str = join ' ',
			map
			{ sprintf('%s/%s', $_, ($_->VERSION // 'undef')) }
			qw/WWW::DataWiki Catalyst RDF::Trine RDF::TriN3 RDF::Query/;
		$ctx->res->header(X_Powered_By => $str);
		
		if (blessed($resource))
		{
			$ctx->forward( $ctx->view('General') );
		}
	}
}
