C:\Perl_PPM\Bread-Board-0.33\blib/lib/Bread/Board/Container.pm |
add_service
get_service
has_service
has_services
get_service_list
add_sub_container
get_sub_container
has_sub_container
has_sub_containers
get_sub_container_list
add_type_mapping_for
get_type_mapping_for
has_type_mapping_for
resolve
Bread::Board::Container
version 0.33
This class implements the container for the Bread::Board manpage: a container is a thing that contains services and other containers. Each container and service has a name, so you end up with a tree of named nodes, just like files and directories in a filesystem: each item can be referenced using a path (see the Bread::Board::Traversable manpage for the details).
name
Read/write string, required. Every container needs a name, by which it can be referenced when fetching it.
services
Hashref, constrained by < Bread::Board::Container::ServiceList
>, mapping names to services directly contained in this
container. Every service added here will have its < parent
> set to this container.
You can pass an arrayref of services instead of a hashref, the keys will be the names of the services.
You should probably use add_service and get_service to manipulate this attribute, instead of modifying it directly.
sub_containers
Hashref, constrained by < Bread::Board::Container::SubContainerList
>, mapping names to containers directly contained in this
container. Every container added here will have its < parent
> set to this container.
You can pass an arrayref of containers instead of a hashref, the keys will be the names of the containers.
You should probably use add_sub_container and get_sub_container to manipulate this attribute, instead of modifying it directly.
Containers added here can either be normal the Bread::Board::Container manpage or the Bread::Board::Container::Parameterized manpage.
add_service
$container->add_service($service);
Adds a service into the services map, using its name as the key.
get_service
my $service = $container->get_service($name);
Returns a service by name, or undef
if there's no such service in
the services map.
has_service
if ($container->has_service($name)) { ... }
Returns true if a service with the given name name exists in the services map, false otherwise.
has_services
if ($container->has_services) { ... }
Returns true if the services map contains any services, false if it's empty.
get_service_list
my @service_names = $container->get_service_list();
Returns the names off all services present in the services map.
add_sub_container
$container->add_sub_container($container);
Adds a container into the sub_containers map, using its name as the key.
get_sub_container
my $container = $container->get_sub_container($name);
Returns a container by name, or undef
if there's no such container
in the sub_containers map.
has_sub_container
if ($container->has_sub_container($name)) { ... }
Returns true if a container with the given name name exists in the sub_containers map, false otherwise.
has_sub_containers
if ($container->has_sub_containers) { ... }
Returns true if the sub_containers map contains any contains, false if it's empty.
get_sub_container_list
my @container_names = $container->get_sub_container_list();
Returns the names off all containers present in the sub_containers map.
add_type_mapping_for
$containers->add_type_mapping_for( $type_name, $service );
Adds a mapping from a Moose type to a service: whenever we try to resolve that type, we'll use that service to instantiate it.
get_type_mapping_for
my $service = $container->get_type_mapping_for( $type_name );
Returns the service to use to instantiate the given type name.
Important: if a mapping for the exact type can't be found, but a mapping for a subtype of it can, you'll get the latter instead:
package Superclass { use Moose }; package Subclass { use Moose; exends 'Superclass' };
$c->add_type_mapping_for( 'Subclass', Bread::Board::ConstructorInjection->new(name=>'sc',class=>'Subclass'), ); my $o = $c->get_type_mapping_for('Superclass')->get;
$o
is an instance of Subclass
. If there are more than one
sub-type mapped, you get a random one. This is probably a bad idea.
has_type_mapping_for
if ($container->has_type_mapping_for( $type_name )) { ... }
Returns true if we have a service defined to instantiate the given type name, but see the note on get_type_mapping_for about subtype mapping.
resolve
my $object = $container->resolve(service=>$service_name); my $object = $container->resolve(service=>$service_name,parameters=>\%p);
When given a service name, this method will
fetch the service, then call < get
> on it, optionally passing the
given parameters.
my $object = $container->resolve(type=>$type); my $object = $container->resolve(type=>$type,parameters=>\%p);
When given a type name, this method will use
get_type_mapping_for to get
the service, then call get
on it,
optionally passing the given parameters. If the instance is not of the
expected type, the method will die.
Stevan Little <stevan@iinteractive.com>
Please report any bugs or feature requests on the bugtracker website https://github.com/stevan/BreadBoard/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
This software is copyright (c) 2015 by Infinity Interactive.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
C:\Perl_PPM\Bread-Board-0.33\blib/lib/Bread/Board/Container.pm |