Get sugar working
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC.pm
CommitLineData
2336ae0b 1package Catalyst::IOC;
fb7aaa61 2use strict;
3use warnings;
7e3dbfea 4use Bread::Board;
71d3df94 5use Catalyst::IOC::ConstructorInjection;
2336ae0b 6
7e3dbfea 7# FIXME - neither of these work:
71d3df94 8use Sub::Exporter -setup => {
9 exports => [qw/
10 component
11 /],
12 groups => { default => [qw/
13 component
14 /]},
15};
7e3dbfea 16#use Sub::Exporter -setup => [
17# qw(
18# Bread::Board::as
19# Bread::Board::container
20# Bread::Board::depends_on
21# Bread::Board::service
22# Bread::Board::alias
23# Bread::Board::wire_names
24# Bread::Board::include
25# Bread::Board::typemap
26# Bread::Board::infer
27# )
28#];
29# I'm probably doing it wrong.
30# Anyway, I'll just use Moose::Exporter. Do I really have to use Sub::Exporter?
71d3df94 31#use Moose::Exporter;
32#Moose::Exporter->setup_import_methods(
33# also => ['Bread::Board'],
34#);
35
36sub component {
37 my ($name, %args) = @_;
38 $args{dependencies} ||= {};
39 $args{dependencies}{application_name} = depends_on( '/application_name' );
40
41 # FIXME - check $args{type} here!
42
43 Catalyst::IOC::ConstructorInjection->new(
44 %args,
45 name => $name,
46 lifecycle => 'Singleton',
47 # XX FIXME - needs to become possible to intuit catalyst_component_name
48 # from dependencies (like config)
49 catalyst_component_name => 'TestAppCustomContainer::Model::Bar',
50 )
51}
2336ae0b 52
fb7aaa61 531;
51f62e09 54
4e4e003e 55# FIXME - should the code example below be on this file or Catalyst::IOC::Container?
56
51f62e09 57__END__
58
59=pod
60
61=head1 NAME
62
63Catalyst::IOC - IOC for Catalyst, based on Bread::Board
64
65=head1 SYNOPSIS
66
4e4e003e 67 package MyApp::Container;
68 use Catalyst::IOC;
69
70 sub BUILD {
71 my $self = shift;
72
73 container $self => as {
74 container model => as {
75
76 # default component
77 component Foo => ();
78
79 # model Bar needs model Foo to be built before
80 # and Bar's constructor gets Foo as a parameter
81 component Bar => ( dependencies => [
82 depends_on('/model/Foo'),
83 ]);
84
85 # Baz is rebuilt once per HTTP request
86 component Baz => ( lifecycle => 'Request' );
87
88 # built only once per application life time
89 component Quux => ( lifecycle => 'Singleton' );
90
91 # built once per app life time and uses an external model,
92 # outside the default directory
93 # no need for wrappers or Catalyst::Model::Adaptor
94 component Fnar => (
95 lifecycle => 'Singleton',
96 class => 'My::External::Class',
97 );
98 };
99 }
100 }
101
51f62e09 102=head1 DESCRIPTION
103
104=head1 METHODS
105
106=head1 AUTHORS
107
108Catalyst Contributors, see Catalyst.pm
109
4e4e003e 110=head1 SEE ALSO
111
112L<Bread::Board>
113
51f62e09 114=head1 COPYRIGHT
115
116This library is free software. You can redistribute it and/or modify it under
117the same terms as Perl itself.
118
119=cut