Class::DI - Perl dependency injection container
injections: - name: hoge class_name: Hoge injection_type: setter instance_type: prototype properties: name: hoge - name: fuga class_name: Fuga injection_type: constructer instance_type: singleton properties: name: fuga - name: hogehoge class_name: HogeHoge injection_type: constructer instance_type: singleton properties: hogehoge: name: fugafuga class_name: FugaFuga injection_type: constructer instance_type: singleton properties: name: fugafuga my $di = Class::DI->yaml_container($yaml_filepath); # set from set_name method # $hoge->set_name("hoge"); my $hoge = $di->get_component("hoge"); print $hoge->get_name; # hoge # set from constructer # Fuga->new({name=>"fuga"}); my $fuga = $di->get_component("fuga"); print $fuga->get_name; # fuga # nested class my $hogehoge = $di->get_component("hogehoge"); print $hogehoge->get_fugafuga->get_name; # fugafuga
this class does DI. The instance is generated based on an external setting, and the dependence between components is excluded from the source code.
Masafumi Yoshida, <masafumi.yoshida820@gmail.com>
Copyright (C) 2010 by masafumi yoshida
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install Class::DI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::DI
CPAN shell
perl -MCPAN -e shell install Class::DI
For more information on module installation, please visit the detailed CPAN module installation guide.