| Catalyst-Plugin-Singleton documentation | Contained in the Catalyst-Plugin-Singleton distribution. |
Catalyst::Plugin::Singleton - Singleton to context
use Catalyst qw[Singleton];
# Retrieve a instance of context
my $c = MyApp->instance;
my $c = MyApp->context;
Singleton accessors to context.
alias for instance
Returns the current instance of the context object.
Christian Hansen, ch@ngmedia.com
This library is free software. You can redistribute it and/or modify it under the same terms as perl itself.
| Catalyst-Plugin-Singleton documentation | Contained in the Catalyst-Plugin-Singleton distribution. |
package Catalyst::Plugin::Singleton; use strict; use Scalar::Util; our $VERSION = '0.02'; *context = \&instance; sub instance { my $class = shift; no strict 'refs'; return ${"$class\::_instance"}; } sub prepare { my $class = shift; my $context = $class->NEXT::prepare(@_); { no strict 'refs'; Scalar::Util::weaken( ${"$class\::_instance"} = $context ); } return $context; } 1; __END__