Tema Novikov

NAME

Crane - Helpers for development in Perl

SYNOPSIS

  use Crane;
  
  ...
  
  use Crane ( 'name' => 'example' );

DESCRIPTION

Helpers for development in Perl. Includes the most modern technics and rules.

Also imports modules as "Crane::Base" in Crane::Base;

Import options

You can specify these options when using module:

name

Script name, used when run as daemon.

If defined, run as daemon by default. Use --no-daemon command line option to cancel this behavior.

base

Array (reference) to list of base modules.

options

Array (reference) of options which will be added to the head of default options list.

config

Hash (reference) with user defined default settings.

namespace

Custom namespace. Please, look at examples below.

OPTIONS

These options are available by default. You can define your custom options if specify it in the import options.

-M, --daemon, --no-daemon

Runs as daemon.

-C path/to/config, --config=path/to/config

Path to configuration file.

-P path/to/file_with.pid, --pid=path/to/file_with.pid

Path to PID file.

-O path/to/messages.log, --log=path/to/messages.log

Path to messages log file.

-E path/to/errors.log, --log-error=path/to/errors.log

Path to errors log file.

-D, --debug, --no-debug

Debug output.

-V, --verbose, --no-verbose

Verbose output.

--version

Shows version information and exits.

--help

Shows help and exits.

RETURN VALUE

In case of running as daemon will return 1 if process is already running.

DIAGNOSTICS

Process is already running: %d

Where %d is a PID.

You tried to run application as daemon while another copy is running.

EXAMPLES

Singleton usage

  use Crane;
  
  ...
  
  use Crane ( 'base' => qw( Mojolicious::Controller ) );

Daemon usage

  use Crane ( 'name' => 'example' );

Configure options

  use Crane ( 'options' => [
      [ 'from|F=s', 'Start of the interval.', { 'required' => 1 } ],
      [ 'to|F=s',   'End of the interval.',   { 'required' => 1 } ],
  ] );

As a result you have these two options, a separator and default options.

Basic namespace usage

  package My;
  
  use Crane (
      'namespace' => 'My',
      
      'config' => {
          'my' => {
              'autorun' => 1,
              
              'hosts' => [
                  '127.0.0.1',
                  '127.0.0.2',
              ],
          },
      },
  );
  
  1;
  
  ...
  
  use My;
  use My::Config;
  use My::Logger;
  
  log_info(config->{'log'});

Advanced namespace usage

  package My;
  
  use Crane::Base;
  use Crane::Options qw( :opts );
  
  require Crane;
  
  sub import {
      my ( $package, $name ) = @_;
      
      Crane->import(
          'namespace' => 'My',
          'name'      => $name,
          
          'options' => [
              [ 'run!',    'Do action at startup.' ],
              $OPT_SEPARATOR,
              [ 'host=s@', 'Host name(s).' ],
          ],
          
          'config' => {
              'my' => {
                  'autorun' => 1,
                  
                  'hosts' => [
                      '127.0.0.1',
                      '127.0.0.2',
                  ],
              },
          },
      );
      
      return;
  }
  
  1;
  
  ...
  
  use My 'my_script';
  
  sub main {
      ...
      
      return 0;
  }
  
  exit main();

ENVIRONMENT

See Crane::Base.

FILES

etc/*.conf

Configuration files. See Crane::Config.

log/*.log

Log files. See Crane::Logger.

run/*.pid

Script's PID file.

BUGS

Please report any bugs or feature requests to https://rt.cpan.org/Public/Bug/Report.html?Queue=Crane or to https://github.com/temoon/crane/issues.

AUTHOR

Tema Novikov, <novikov.tema@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2013-2014 Tema Novikov.

This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license in the file LICENSE.

SEE ALSO