Catalyst-Component-ACCEPT_CONTEXT

 view release on metacpan or  search on metacpan

lib/Catalyst/Component/ACCEPT_CONTEXT.pm  view on Meta::CPAN

package Catalyst::Component::ACCEPT_CONTEXT;

use warnings;
use strict;
use MRO::Compat;
use Scalar::Util qw(weaken);

=head1 NAME

Catalyst::Component::ACCEPT_CONTEXT - Make the current Catalyst
request context available in Models and Views.

=head1 VERSION

Version 0.07

lib/Catalyst/Component/ACCEPT_CONTEXT.pm  view on Meta::CPAN


See L<Catalyst::Component> for details.

=cut

sub ACCEPT_CONTEXT {
    my $self    = shift;
    my $context = shift;

    $self->{context} = $context;
    weaken($self->{context});

    return $self->maybe::next::method($context, @_) || $self;
}

=head2 COMPONENT

Overridden to use initial application object as context before a request.

=cut

sub COMPONENT {
    my $class = shift;
    my $app   = shift;
    my $args  = shift;
    $args->{context} = $app;
    weaken($args->{context}) if ref $args->{context};
    return $class->maybe::next::method($app, $args, @_);
}

=head1 AUTHOR

Jonathan Rockway, C<< <jrockway at cpan.org> >>

Patches contributed and maintained by:

=over

t/lib/TestApp/Controller/Root.pm  view on Meta::CPAN

    my $got_cycle = sub { $cycle_ok = 0 };
    find_cycle($c, $got_cycle);
    $c->res->body($cycle_ok);
} 

sub weak_cycle :Global {
    my ($self, $c) = @_;
    $c->model('StashMe')->test;
    my $cycle_ok = 0;
    my $got_cycle = sub { $cycle_ok = 1 };
    find_weakened_cycle($c, $got_cycle);
    $c->res->body($cycle_ok);
}

1;



( run in 0.606 second using v1.01-cache-2.11-cpan-65fba6d93b7 )