Context-Singleton

 view release on metacpan or  search on metacpan

lib/Context/Singleton/Tutorial.pod  view on Meta::CPAN

=encoding utf-8

=head1 NAME

Context::Singleton::Tutorial - How to work with Context::Singleton

=head1 TASK

Let's have an application handling web requests and emails, eg ticket system.

Application has config file providing database credentials.

=head1 IMPLEMENTATION

=head2 Root context resources

Root context is default context provided by Context::Singleton.
Resources defined in this context are real singletons.

=head3 Rule config_file

lib/Context/Singleton/Tutorial.pod  view on Meta::CPAN


Let's upgrage our application so we will have one database per user
but still using central database for user authentication.

=over

=item Override resources after using them

	sub do_something {
		my $db = deduce 'db';
		my ($dsn, $user, $password) = $db->fetch_user_db_credentials;
		frame {
			proclaim db_dsn => $dsn;
			proclaim db_user => $user;
			proclaim db_password => $password;
			# db will be recaluclated when requested
			...;
		};
	}

=item Change user db rule and link it with db



( run in 0.231 second using v1.01-cache-2.11-cpan-4d50c553e7e )