GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MOOSEX::IOC (3)

.ds Aq ’

NAME

MooseX::IOC - Moose attributes with IOC integration

CONTENTS

SYNOPSIS



  # in a startup script somewhere ...

  use IOC;
  use IOC::Service::Parameterized;
  use IOC::Registry;
  use MooseX::IOC;

  {
      my $container = IOC::Container->new(MyProject);
      $container->register(IOC::Service::Literal->new(log_file => "logfile.log"));
      $container->register(IOC::Service->new(FileLogger => sub {
          my $c = shift;
          return FileLogger->new($c->get(log_file));
      }));

      my $reg = IOC::Registry->new;
      $reg->registerContainer($container);
  }

  # in a .pm file somewhere ...

  package MyApplication;
  use Moose;

  has logger => (
      metaclass => IOC,
      is        => ro,
      isa       => FileLogger,
      service   => /MyProject/FileLogger,
  );

  # in a script file somewhere ...

  my $app = MyApplication->new;
  $app->logger; # automatically gotten from IOC



DESCRIPTION

This module provides a bridge between IOC registries and Moose objects through a custom attribute metaclass. It compliments the default option with a service option which contains a IOC::Registry path (and optional parameters).

The service option can be in one of the following formats:
IOC::Registry path string This is the simplest version available, it is simply a path string which can be passed to IOC::Registry’s locateService method.
IOC::Registry path string and parameters This version is for use with IOC::Service::Parameterized services, and allows you to pass additional parameters to the locateService method. It looks like this:



  has logger => (
      metaclass => IOC,
      is        => ro,
      isa       => FileLogger,
      service   => [ /MyProject/FileLogger => (log_file => foo.log) ],
  );



CODE reference The last version is the most flexible, it is CODE reference which is expected to return an ARRAY ref similar to the above version.



  has logger => (
      metaclass => IOC,
      is        => ro,
      isa       => FileLogger,
      lazy      => 1,
      service   => sub {
          my $self = shift;
          [ /MyProject/FileLogger => (
                log_file => $self->log_file
            ) ]
      },
  );



If the service is not found and a default option has been set, then it will return the value in default. This can be useful for writing code which can potentially be run both under IOC and not under IOC.

METHODS

<B>metaB>

SEE ALSO

IOC
IOC::Registry
Moose

BUGS

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

AUTHOR

Stevan Little <stevan@iinteractive.com>

COPYRIGHT AND LICENSE

Copyright 2007-2009 by Infinity Interactive, Inc.

<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 MOOSEX::IOC (3) 2009-06-29

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.