MooseX-DIC

 view release on metacpan or  search on metacpan

lib/MooseX/DIC/Configuration/ServiceMetadata.pm  view on Meta::CPAN

use Moose;
use namespace::autoclean;

use constant DEFAULT_ENVIRONMENT => 'default';
use constant DEFAULT_SCOPE => 'singleton';
use constant DEFAULT_BUILDER => 'Moose';

has class_name => ( is => 'ro', isa => 'Str', required => 1 );
has implements => ( is => 'ro', isa => 'Str', required => 1 );
has scope      => ( is => 'ro', isa => 'ServiceScope', default => DEFAULT_SCOPE );
has qualifiers => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] } );
has environment => ( is => 'ro', isa => 'Str', default => DEFAULT_ENVIRONMENT );
has builder => ( is => 'ro', isa => 'Str', default => DEFAULT_BUILDER );
has dependencies => ( is => 'ro', isa => 'HashRef[MooseX::DIC::Configuration::ServiceMetadata::Dependency]', default => sub {{}} );

__PACKAGE__->meta->make_immutable;

1;

lib/MooseX/DIC/Configuration/ServiceMetadata/Dependency.pm  view on Meta::CPAN

use Exporter::Declare;

use Moose;

use MooseX::DIC::Types;

exports qw/ from_attribute from_yaml/;

has name => (is => 'ro', isa => 'Str', required => 1);
has scope => ( is => 'ro', isa => 'InjectionScope', default => 'object' );
has qualifiers => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] } );

# ( attribute: Moose::Meta::Attribute ) -> :Dependency
sub from_attribute {
  my $attribute = shift;
  
  my %params = ( name => $attribute->name );
  if( $attribute->does('MooseX::DIC::Injected') ) {
    $params{scope} = $attribute->scope if $attribute->scope;
    $params{qualifiers} = $attribute->qualifiers if $attribute->qualifiers;
  }

lib/MooseX/DIC/Container/DefaultImpl.pm  view on Meta::CPAN

use MooseX::DIC::ServiceFactoryFactory 'build_factory';
use Module::Load;
use Try::Tiny;

use Moose;
with 'MooseX::DIC::Container';
with 'MooseX::DIC::Loggable';

has environment => ( is => 'ro', isa => 'Str', default => 'default' );
has registry => (is => 'ro', isa => 'MooseX::DIC::ServiceRegistry', required => 1);
has singletons => (is => 'ro', isa => 'HashRef[HashRef[Any]]', default => sub { { default => {} } });
has service_factories => ( is => 'ro', isa => 'HashRef[ServiceFactory]', default => sub { {} } );

sub has_service {
  my ( $self, $interface_name ) = @_;

  return $self->registry->has_service($interface_name);
}

sub build_class {
  my ($self,$package_name) = @_;

lib/MooseX/DIC/ContainerFactory.pm  view on Meta::CPAN


use Moose;
with 'MooseX::DIC::Loggable';

use aliased 'MooseX::DIC::Container::DefaultImpl';
use aliased 'MooseX::DIC::Configuration::Code';
use aliased 'MooseX::DIC::Configuration::YAML';
use List::Util 'reduce';

has environment => (is => 'ro', isa => 'Str', default => 'default' );
has scan_path => ( is => 'ro', isa => 'ArrayRef[Str]', required => 1 );

sub build_container {
	my ($self) = @_;

	# Build the registry
	$self->logger->debug("Building the registry for the container...");
	my $registry = MooseX::DIC::ServiceRegistry->new;
	$self->_apply_config_to($registry);
	$self->logger->debug($registry->services_count." services registered");
	

lib/MooseX/DIC/Injected.pm  view on Meta::CPAN

package MooseX::DIC::Injected;

use Moose::Role;
Moose::Util::meta_attribute_alias('Injected');

use MooseX::DIC::Types;

has scope => ( is => 'ro', isa => 'InjectionScope', default => 'object' );
has qualifiers =>
    ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] } );

1;

lib/MooseX/DIC/ServiceRegistry.pm  view on Meta::CPAN

package MooseX::DIC::ServiceRegistry;

use Moose;
with 'MooseX::DIC::Loggable';

# InterfaceName -> EnvironmentName => ServiceMetadata
has metadata => ( is => 'ro', isa => 'HashRef[HashRef[MooseX::DIC::Configuration::ServiceMetadata]]', default => sub { {} } );


# (interface_name: Str) -> Bool
sub has_service {
  my ($self,$interface_name) = @_;

  return exists($self->metadata->{$interface_name});
}

# (service_metadata: ServiceMetadata) -> Void



( run in 0.683 second using v1.01-cache-2.11-cpan-5f2e87ce722 )