NAME

Module::Generate - Assisting with module generation.

VERSION

Version 1.01

SYNOPSIS

use Module::Generate;

Module::Generate->dist('Plane')
	->author('LNATION')
	->email('email@lnation.org')
	->version('0.01')
	->class('Plane')
		->abstract('Plane')
		->our('$type')
		->begin(sub {
			$type = 'boeing';
		})
		->new
			->pod('Instantiate a new plane.')
			->example('my $plane = Plane->new')
		->accessor('airline')
		->sub('type')
			->code(sub { $type })
			->pod('Returns the type of plane.')
			->example('$plane->type')
		->sub('altitude')
			->code(sub {
				$_[1] / $_[2];
				...
			})
			->pod('Discover the altitude of the plane.')
			->example('$plane->altitude(100, 100)')
	->generate;

...

Module::Generate->dist('Holiday')
	->author('LNATION')
	->email('email@lnation.org')
	->version('0.01')
	->class('Feed::Data')
		->use('Data::LnArray')
		->our('$holiday')
		->begin(sub {
			$holiday = Data::LnArray->new;
		})
		->sub('parse')
		->sub('write')
		->sub('render')
		->sub('generate')
		->sub('_raw')
		->sub('_text')
		->sub('_json')
	->generate;

SUBROUTINES/METHODS

start

Instantiate a new Module::Generate object.

my $mg = Module::Generate->start;	

dist

Provide a name for the distribution.

my $dist = Module::Generate->dist('Plane');

lib

Provide a path where the generated files will be compiled.

my $module = Module::Generate->lib('./path/to/lib');

tlib

Provide a path where the generated test will be compiled.

my $module = Module::Generate->tlib('./path/to/t');

author

The author of the distribution/module.

my $module = Module::Generate->author('LNATION');

email

The authors email of the distribution/module.

my $module = Module::Generate->email('email@lnation.org');

version

The version number of the distribution/module.

my $version = Module::Generate->version('0.01');

class

Start a new class/package/module..

my $class = Module::Generate->class('Plane');

abstract

Provide abstract text for the class.

$class->abstract('Over my head.');

synopsis

Provide a synopsis for the class.

$class->synopsis('...');

no_strict

Disable strict by flag.

$class->no_strict('refs');

no_warnings

Disable warnings by flag.

$class->no_warnings('reserved');

use

Declare modules that should be included in the class.

$class->use(qw/Moo MooX::LazierAttributes/);

base

Establish an ISA relationship with base classes at compile time.

Unless you are using the fields pragma, consider this discouraged in favor of the lighter-weight parent.

$class->base(qw/Foo Bar/);

parent

Establish an ISA relationship with base classes at compile time.

$class->parent(qw/Foo Bar/);

require

Require library files to be included if they have not already been included.

$class->require(qw/Foo Bar/);

our

Declare variable of the same name in the current package for use within the lexical scope.

$class->our(qw/$one $two/);

begin

Define a code block is executed as soon as possible.

$class->begin(sub {
	...
});

unitcheck

Define a code block that is executed just after the unit which defined them has been compiled.

$class->unitcheck(sub {
	...
});

check

Define a code block that is executed just after the initial Perl compile phase ends and before the run time begins.

$class->check(sub {
	...
});

init

Define a code block that is executed just before the Perl runtime begins execution.

$class->init(sub {
	...
});

end

Define a code block is executed as late as possible.

$class->end(sub {
	...
});

new

Define an object constructor.

$class->new;

equivalent to:

sub new {
	my ($cls, %args) = (shift, scalar @_ == 1 ? %{$_[0]} : @_);
	bless \%args, $cls;	
}

optionally you can pass your own sub routine.

$class->new(sub { ... });

accessor

Define a accessor.

$class->accessor('test');

equivalent to:

sub test {	
	my ($self, $value) = @_;
	if ($value) {
		$self->{$sub} = $value;
	}
	return $self->{$sub}
}";

sub

Define a sub routine/method.

my $sub = $class->sub('name');

code

Define the code that will be run for the sub.

$sub->code(sub {
	return 'Robert';
});

pod

Provide pod text that describes the sub.

$sub->pod('What is my name?');

example

Provide a code example which will be suffixed to the pod definition.

$sub->example('$foo->name');

test

Provide tests for the sub.

$sub->test(['is', '$obj->name', q|'test'|], [ ... ], ...)

macro

Implement a macro that can be inserted across classes.

my $mg = Module::Generate->author('LNATION')
	->email('email@lnation.org')
	->version('0.01');
$mg->macro('self', sub {
	my ($self, $value) = @_;
});
my $class = $mg->class('Foo');
$class->sub('bar')
	->code(sub { &self; $value; });
$mg->generate;

###

package Foo;
use strict;
use warnings;
our $VERSION = 0.01;

sub bar {
	my ( $self, $value ) = @_;

	$value;
}

1;

__END__

keyword

Implement a keyword that can be used accross classes.

my $mg = Module::Generate
	->author('LNATION')
	->email('email@lnation.org');
$mg->keyword('with', sub {
	my ($meta) = @_;
	return qq|with $meta->{with};|;
});

$mg->keyword('has',
	CODE => sub {
		my ($meta) = @_;
		$meta->{is} ||= q|'ro'|;
		my $attributes = join ', ', map {
			($meta->{$_} ? (sprintf "%s => %s", $_, $meta->{$_}) : ())
		} qw/is required/;
		my $code = qq|
			has $meta->{has} => ( $attributes );|;
		return $code;
	},
	KEYWORDS => [qw/is required/],
	POD_TITLE => 'ATTRIBUTES',
	POD_POD => 'get or set $keyword',
	POD_EXAMPLE => "\$obj->\$keyword;\n\n\t\$obj->\$keyword(\$value);"
);

$mg->class('Keyword')
	->use('Moo')
	->with(qw/'Keyword::Role'/)
		->test(
			['ok', q|my $obj = Keyword->new( thing => 'abc', test => 'def' )|],
			['is', q|$obj->test|, q|'def'|]
		)
	->has('thing')->required(1)
		->test(
			['ok', q|my $obj = Keyword->new( thing => 'abc' )|],
			['is', q|$obj->thing|, q|'abc'|],
			['eval', q|$obj = Keyword->new()|, 'required']
		);

$mg->class('Keyword::Role')
	->use('Moo::Role')
	->has('test')->is(q|'rw'|)
		->test(
			['ok', q|my $obj = do { eval q{
				package FooBar;
				use Moo;
				with 'Keyword::Role';
				1;
			}; 1; } && FooBar->new| ],
			['is', q|$obj->test|, q|undef|],
			['ok', q|$obj->test('abc')|],
			['is', q|$obj->test|, q|'abc'|]
		);

generate

Compile the code.

$sub->generate();

AUTHOR

LNATION, <email at lnation.org>

BUGS

Please report any bugs or feature requests to bug-module-generate at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Module-Generate. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Module::Generate

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2020 by LNATION.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)