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