package IOC::Config::XML; use strict; use warnings; our $VERSION = '0.03'; use IOC::Exceptions; use IOC::Config::XML::SAX::Handler; use XML::SAX::ParserFactory; sub new { my ($_class) = @_; my $class = ref($_class) || $_class; my $config = { _config => {} }; bless($config, $class); return $config; } sub read { my ($self, $source) = @_; (defined($source) && $source) || throw IOC::InsufficientArguments "You must provide something to read"; my $handler = IOC::Config::XML::SAX::Handler->new(); my $p = XML::SAX::ParserFactory->parser(Handler => $handler); if ($source =~ /\.xml$/) { $p->parse_uri($source); } else { $p->parse_string($source); } } 1; __END__ =head1 NAME IOC::Config::XML - An XML Config reader for IOC =head1 SYNOPSIS use IOC::Config::XML; my $conf_reader = IOC::Config::XML->new(); $conf_reader->read('my_ioc_conf.xml'); # now the IOC::Registry singleton is all configured =head1 DESCRIPTION This is the second version of an XML configuration module for IOC. The first version used L, which is a great module, but not really the best fit for this. I have now ported this over to use L, which is much more flexible solution (not to mention a really nice way to interact with XML). I consider this module to be late-BETA quality (it is currently in production and working without issue for a month now). =head1 SAMPLE XML CONF ERegistryE EContainer name='Application'E EContainer name='Database'E EService name='dsn' type='Literal'Edbi:Mock:E/ServiceE EService name='username' type='Literal'EuserE/ServiceE EService name='password' type='Literal'E****E/ServiceE EService name='connection' type='ConstructorInjection' prototype='true'E EClass name='DBI' constructor='connect' /E EParameter type='component'EdsnE/ParameterE EParameter type='component'EusernameE/ParameterE EParameter type='component'EpasswordE/ParameterE E/ServiceE E/ContainerE EService name='logger_table' type='Literal'Etbl_logE/ServiceE EService name='logger' type='SetterInjection'E EClass name='My::DB::Logger' constructor='new' /E ESetter name='setDBIConnection'E/Database/connectionE/SetterE ESetter name='setDBTableName'Elogger_tableE/SetterE E/ServiceE EService name='template_factory' type='ConstructorInjection'E EClass name='My::Template::Factory' constructor='new' /E EParameter type='perl'E[ path =E 'test' ]E/ParameterE E/ServiceE EService name='app'E E![CDATA[ my $c = shift; my $app = My::Application-Enew(); $app-EsetLogger($c-Eget('logger')); return $app; ]]E E/ServiceE E/ContainerE E/RegistryE =head1 METHODS =over 4 =item B Create a new XML::Config::XML object to read a configuration and intialize the L. =item B Given an XML C<$source> file or string, this will read the XML in it and intialize the L singleton. =back =head1 TO DO =over 4 =item Handle Includes I thought this will be implemented when I moved to XML::SAX, but it didn't. I am thinking I will try to handle this on my own instead of trying to use XML tricks =item Handle Aliasing This is a minor feature of IOC::Registry, but I want to support it in here eventually. It shouldn't be a problem really, just don't currently have a need to get it in place. =item Handle IOC::Proxy objects It would be nice if you could configure IOC::Proxy objects through XML as well. =back =head1 BUGS None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it. =head1 CODE COVERAGE I use B to test the code coverage of my tests, see the CODE COVERAGE section of L for more information. =head1 SEE ALSO =over 4 =item L =item L =back =head1 AUTHOR stevan little, Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2004-2007 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut