The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Object::Composer - Simple helper to load classes automatically and instantiate them


  use Object::Composer;

  my $neo = load 'My::Person', name => 'Neo', job => 'Hacker', age => 'NA';

  # OR ( if you don't want import functions into your space )

  use Object::Composer ();

  my $morpheus = Object::Composer->load( 'My::Person', name => 'morpheus', job => 'warrior', age => 'NA' );

  # OR ( You can call it as Class Method or as Function in Object::Composer's namespace )

  my $morpheus = Object::Composer::load( 'My::Person', name => 'morpheus', job => 'warrior', age => 'NA' );


This is a simple helper class that helps loading class automatically, instantiate an object and return it. It assumes that 'new' method is already defined in the loaded class, which is what it calls to instantiate the object.

croaks if theres any error while loading or instantiating.

load $class, @args

This is the only function / method defined. It loads the package / module, calls "new" on the class with arguments you pass, and returns the instantiated object.

  $obj = load 'LWP::UserAgent', agent => 'My Own Secret Agent';

  # OR

  $obj = Object::Composer->load( 'HTML::TreeBuilder' );


Venkatakrishnan Ganesh <>


This library is free software and may be distributed under the same terms as perl itself.