X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FIOC.pm;h=0c6ad6eac798a834be562f5b7394fd969addddca;hb=7cd05fd23b8593ff14e73c068817f5fa62ce698a;hp=a20429538f095eb4d28cb15e0a4f3bbd47394c86;hpb=4e4e003e3c915e6e4d3b9f2a97c0d458ffa4ae9c;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/IOC.pm b/lib/Catalyst/IOC.pm index a204295..0c6ad6e 100644 --- a/lib/Catalyst/IOC.pm +++ b/lib/Catalyst/IOC.pm @@ -2,21 +2,24 @@ package Catalyst::IOC; use strict; use warnings; use Bread::Board; - -# FIXME - neither of these work: -#use Sub::Exporter -setup => [ -# qw( -# as -# container -# depends_on -# service -# alias -# wire_names -# include -# typemap -# infer -# ) -#]; +use Catalyst::IOC::ConstructorInjection; + +# FIXME - All of these imports need to get the importing package +# as the customise_container and current_container variables +# NEED to be in the containers package so there can be multiple +# containers.. +use Sub::Exporter -setup => { + exports => [qw/ + component + model + container + /], + groups => { default => [qw/ + component + model + container + /]}, +}; #use Sub::Exporter -setup => [ # qw( # Bread::Board::as @@ -32,10 +35,45 @@ use Bread::Board; #]; # I'm probably doing it wrong. # Anyway, I'll just use Moose::Exporter. Do I really have to use Sub::Exporter? -use Moose::Exporter; -Moose::Exporter->setup_import_methods( - also => ['Bread::Board'], -); +#use Moose::Exporter; +#Moose::Exporter->setup_import_methods( +# also => ['Bread::Board'], +#); +our $customise_container; +our $current_container; + +sub container (&) { + my $code = shift; + $customise_container = sub { + warn("In customise container"); + local $current_container = shift(); + $code->(); + }; +} + +sub model (&) { + my $code = shift; + local $current_container = $current_container->get_sub_container('model'); + $code->(); +} + +sub component { + my ($name, %args) = @_; + $args{dependencies} ||= {}; + $args{dependencies}{application_name} = depends_on( '/application_name' ); + + # FIXME - check $args{type} here! + + my $service = Catalyst::IOC::ConstructorInjection->new( + %args, + name => $name, + lifecycle => 'Singleton', + # XX FIXME - needs to become possible to intuit catalyst_component_name + # from dependencies (like config) + catalyst_component_name => 'TestAppCustomContainer::Model::Bar', + ); + $current_container->add_service($service); +} 1;