CatalystX-Controller-PSGI

 view release on metacpan or  search on metacpan

lib/CatalystX/Controller/PSGI.pm  view on Meta::CPAN

    package TestApp::Controller::File;
    use Moose;
    use namespace::autoclean;

    BEGIN { extends 'CatalystX::Controller::PSGI'; }

    use Plack::App::File;

    has 'app_file' => (
        is      => 'ro',
        default => sub {
            return Plack::App::File->new(
                file            => __FILE__,
                content_type    => 'text/plain',
            )->to_app;
        },
    );

    sub call {
        my ( $self, $env ) = @_;

        $self->app_file->( $env );
    }

    __PACKAGE__->meta->make_immutable;

E.g. in the above example it will be /file/

Works similar to L<Plack::Component>, except that as well as $env being passed in, $self is as well. Where $env is the psgi env, and $self is the Catalyst Controller.

=head2 mount

Mount a path within the controller to an app.

    package TestApp::Controller::Hello;
    use Moose;
    use namespace::autoclean;

    BEGIN { extends 'CatalystX::Controller::PSGI'; }

    use Plack::Response;

    my $hello_app = sub {
        my ( $self, $env ) = @_;

        my $res = Plack::Response->new(200);
        $res->content_type('text/plain');
        $res->body("hello world");

        return $res->finalize;
    };

    __PACKAGE__->mount( '/world' => $hello_app );

    __PACKAGE__->meta->make_immutable;

In the above example the url /hello/world will be bound to the $hello_app. As with call, $self and $env will be passed in.

=head1 EXAMPLES

L<http://www.catalystframework.org/calendar/2013/16>
L<http://www.catalystframework.org/calendar/2013/17>

There is also an example app in the test suite

=head1 AUTHOR

Mark Ellis E<lt>markellis@cpan.orgE<gt>

=head1 SEE ALSO

L<Catalyst::Component::InstancePerContext>

=head1 LICENSE

Copyright 2014 by Mark Ellis E<lt>markellis@cpan.orgE<gt>

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;



( run in 2.105 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )