NAME
Class::GenSource - Generate Perl source code to declare a class
VERSION
This document describes version 0.06 of Class::GenSource (from Perl distribution Class-GenSource), released on 2015-06-12.
SYNOPSIS
use Class::GenSource qw(gen_class_source_code);
say gen_class_source_code(
name => 'My::Class',
attributes => {
foo => {},
bar => {default=>3},
baz => {},
},
);
Will print something like:
package My::Class;
sub new {
my $class = shift;
my $self = bless {@_}, $class;
$self->{bar} = 3 unless exists $self->{bar};
$self;
}
sub foo { my $self = shift; $self->{foo} = $_[0] if @_; $self->{foo} }
sub bar { my $self = shift; $self->{bar} = $_[0] if @_; $self->{bar} }
sub baz { my $self = shift; $self->{baz} = $_[0] if @_; $self->{baz} }
Another example (generating Moo-based class):
say gen_class_source_code(
name => 'My::Class',
attributes => {
foo => {},
bar => {default=>3},
baz => {},
},
variant => 'Moo',
);
will print something like:
package My::Class;
use Moo;
has foo => (is=>'rw');
has bar => (is=>'rw', default=>3);
has baz => (is=>'rw');
DESCRIPTION
FUNCTIONS
gen_class_source_code(%args) -> any
Generate Perl source code to declare a class.
Arguments ('*' denotes required arguments):
attributes => hash (default: {})
name* => str
parent => str
variant => str (default: "classic")
Return value: (any)
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Class-GenSource.
SOURCE
Source repository is at https://github.com/perlancar/perl-Class-GenSource.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Class-GenSource
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.