Module::New::License - Module::New::License documentation


Module-New documentation Contained in the Module-New distribution.

Index


Code Index:

NAME

Top

Module::New::License

SYNOPSIS

Top

  use Module::New::License;
  Module::New::License->render('perl');

DESCRIPTION

Top

This is used internally to render a license text. At the moment, only perl license is supported.

METHOD

Top

render

takes a license name and render the text.

CREATE OTHER LICENSES

Top

  package Your::Module::New::License;
  use Module::New::License 'base';

  license 'license name' => content { my @args = @_; return <<"EOT";
  blah blah blah...
  EOT
  };

With a base flag, domain specific license and content functions will be installed to define custom licenses.

AUTHOR

Top

Kenichi Ishigaki, <ishigaki at cpan.org>

COPYRIGHT AND LICENSE

Top


Module-New documentation Contained in the Module-New distribution.

package Module::New::License;

use strict;
use warnings;
use Carp;
use Sub::Install 'reinstall_sub';

my %LICENSES;

sub _install_dsl {
  my $class = shift;

  return if $class eq 'main';
  return if $class =~ /^Test::/;

  reinstall_sub({
    as   => 'license',
    into => $class,
    code => sub ($$) { 
      my ($name, $text) = @_;
      $LICENSES{$name} = sub { $text->(@_) };
    },
  });

  reinstall_sub({
    as   => 'content',
    into => $class,
    code => sub (&) { return shift },
  });

  reinstall_sub({
    as   => 'render',
    into => $class,
    code => sub {
      my ($self, $type, @args) = @_;

      return $LICENSES{$type}->(@args) if $LICENSES{$type};

      croak "unknown license type: $type";
    }
  });
}

BEGIN { _install_dsl(__PACKAGE__); }

sub import {
  my ($class, $flag) = @_;

  _install_dsl(caller) if $flag && $flag eq 'base';
}

license perl => content { return <<'EOT';
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
EOT
};

1;

__END__