Software::License - packages that provide templated software licenses


Software-License documentation Contained in the Software-License distribution.

Index


Code Index:

NAME

Top

Software::License - packages that provide templated software licenses

VERSION

Top

version 0.103002

SYNOPSIS

Top

  my $license = Software::License::Discordian->new({
    holder => 'Ricardo Signes',
  });

  print $output_fh $license->fulltext;

METHODS

Top

new

  my $license = $subclass->new(\%arg);

This method returns a new license object for the given license class. Valid arguments are:

  holder - the holder of the copyright; required
  year   - the year of copyright; defaults to current year

year

holder

These methods are attribute readers.

name

This method returns the name of the license, suitable for shoving in the middle of a sentence, generally with a leading capitalized "The."

url

This method returns the URL at which a canonical text of the license can be found, if one is available. If possible, this will point at plain text, but it may point to an HTML resource.

notice

This method returns a snippet of text, usually a few lines, indicating the copyright holder and year of copyright, as well as an indication of the license under which the software is distributed.

license

This method returns the full text of the license.

fulltext

This method returns the complete text of the license, preceded by the copyright notice.

version

This method returns the version of the license. If the license is not versioned, this method will return false.

meta_name

This method returns the string that should be used for this license in the CPAN META.yml file, according to the CPAN Meta spec v1, or undef if there is no known string to use.

This method may also be invoked as meta_yml_name for legacy reasons.

meta2_name

This method returns the string that should be used for this license in the CPAN META.json or META.yml file, according to the CPAN Meta spec v2, or undef if there is no known string to use. If this method does not exist, and meta_name returns open_source, restricted, unrestricted, or unknown, that value will be used.

LOOKING UP LICENSE CLASSES

Top

If you have an entry in a META.yml or META.json file, or similar metadata, and want to look up the Software::License class to use, there are useful tools in Software::LicenseUtils.

TODO

Top

SEE ALSO

Top

The specific license:

AUTHOR

Top

Ricardo Signes <rjbs@cpan.org>

COPYRIGHT AND LICENSE

Top


Software-License documentation Contained in the Software-License distribution.

use strict;
use warnings;
use 5.006; # warnings
package Software::License;
BEGIN {
  $Software::License::VERSION = '0.103002';
}
# ABSTRACT: packages that provide templated software licenses

use Data::Section -setup => { header_re => qr/\A__([^_]+)__\Z/ };
use Sub::Install ();
use Text::Template ();


sub new {
  my ($class, $arg) = @_;

  Carp::croak "no copyright holder specified" unless $arg->{holder};

  bless $arg => $class;
}


sub year   { defined $_[0]->{year} ? $_[0]->{year} : (localtime)[5]+1900 }
sub holder { $_[0]->{holder}     }


sub notice { shift->_fill_in('NOTICE') }


sub license { shift->_fill_in('LICENSE') }


sub fulltext {
  my ($self) = @_;
  return join "\n", $self->notice, $self->license;
}


sub version  {
  my ($self) = @_;
  my $pkg = ref $self ? ref $self : $self;
  $pkg =~ s/.+:://;
  my (undef, @vparts) = split /_/, $pkg;

  return unless @vparts;
  return join '.', @vparts;
}


# sub meta1_name    { return undef; } # sort this out later, should be easy
sub meta_name     { return undef; }
sub meta_yml_name { $_[0]->meta_name }

sub meta2_name {
  my ($self) = @_;
  my $meta1 = $self->meta_name;

  return undef unless defined $meta1;

  return $meta1
    if $meta1 =~ /\A(?:open_source|restricted|unrestricted|unknown)\z/;

  return undef;
}

sub _fill_in {
  my ($self, $which) = @_;

  Carp::confess "couldn't build $which section" unless
    my $template = $self->section_data($which);

  return Text::Template->fill_this_in(
    $$template,
    HASH => { self => \$self },
    DELIMITERS => [ qw({{ }}) ],
  );
}


1;




__DATA__
__NOTICE__
This software is Copyright (c) {{$self->year}} by {{$self->holder}}.

This is free software, licensed under:

  {{ $self->name }}