Demian Riccardi
and 1 contributors


HackaMol::X::Roles::ExtensionRole - Role to assist writing HackaMol extensions to external programs


version 0.013


    package HackaMol::X::SomeExtension;
    use Moose;

    with qw(HackaMol::X::Roles::ExtensionRole);

    sub _build_map_in{
      my $sub_cr = sub { return (@_) };
      return $sub_cr;

    sub _build_map_out{
      my $sub_cr = sub { return (@_) };
      return $sub_cr;

    sub BUILD {
      my $self = shift;

      if ( $self->has_scratch ) {
          $self->scratch->mkpath unless ( $self->scratch->exists );

    no Moose;


The HackaMol::X::Roles::ExtensionRole includes methods and attributes that are useful for building extensions with code reuse. This role will improve as extensions are written and needs arise. This role is flexible and can be encapsulated and rigidified in extensions. Advanced use of extensions should still be able to access this flexibility to allow tinkering with internals! Consumes HackaMol::Roles::ExeRole and HackaMol::Roles::PathRole ... ExeRole may be removed from core and wrapped in here.



the main function is to change to scratch directory, if set, and pass all arguments (including self) to map_in CodeRef.


will invoke,

  &{$calc->map_in}(@_);  #where @_ = ($self,@args)

and return anything returned by the map_in function. Thus, any input writing should take place in map_in inorder to actually write to the scratch directory.


completely analogous to map_input. Thus, the output must be opened and processed in the map_out function.


builds the command from the attributes: exe, inputfn, exe_endops, if they exist, and returns the command.


uses Capture::Tiny capture method to run a command using a system call. STDOUT, STDERR, are captured and returned.

  my ($stdout, $stderr,@other) = capture { system($command) }

the $command is taken from $calc->command unless the $command is passed,


capture_sys_command returns ($stdout, $stderr,@other) or 0 if there is no command set.



Coerced to be 'Path::Tiny' via AbsPath. If scratch is set, map_input and map_output will local CWD to the scratch to carry out operations. See HackaMol::PathRole for more information about the scratch attribute and other attributes available (such as in_fn and out_fn).


isa HackaMol::Molecule that is ro


isa CodeRef that is ro. The default builder is required for consuming classes.

intended for mapping input files from molecular information, but it is completely flexible. Used in map_input method. Can also be directly ivoked,


as any other subroutine would be. Extensions can build the map_in function so that it returns the content of $input which can then be written within API methods.


isa CodeRef that is ro. The default builder is required for consuming classes.

intended for mapping molecular information from output files, but it is completely flexible and analogous to map_in.



Demian Riccardi <>


This software is copyright (c) 2016 by Demian Riccardi.

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