#!/bin/sh

###
# = perl.sh(3)
# Miklos Vajna <vmiklos@frugalware.org>
#
# == NAME
# perl.sh - for Frugalware
#
# == SYNOPSIS
# Common schema for Perl CPAN packages.
#
# == EXAMPLE
# --------------------------------------------------
# _F_perl_name=Pod-Simple
# _F_perl_author=A/AR/ARANDAL
# pkgver=3.04
# pkgdesc="framework for parsing Pod"
# depends=('perl-pod-escapes')
# Finclude perl
# pkgrel=1
# archs=('x86_64')
# sha1sums=('45646ac806b91b37caadf0b08ce71d3f6ef2a60c')
# --------------------------------------------------
#
# == OPTIONS
# * _F_perl_name: name of the CPAN module
# * _F_perl_ext (defaults to .tar.gz): extension of the source tarball
# * _F_perl_sourcename (defaults to _F_perl_name): name of the source tarball
# without pkgver and _F_perl_ext
# * _F_perl_url (defaults to http://search.cpan.org/CPAN/authors/id/)
# * _F_perl_no_url: if set, don't overwrite $url
# * _F_perl_no_up2date: if set, don't set $up2date
# * _F_perl_no_source: if set, don't set $source()
###
[ -z "$_F_perl_name" ] && \
{
	error "No \$_F_perl_name set!"
	Fdie
}

[ -z "$_F_perl_ext" ] && _F_perl_ext=".tar.gz"
[ -z "$_F_perl_sourcename" ] && _F_perl_sourcename="$_F_perl_name"
[ -z "$_F_perl_url" ] && _F_perl_url="https://cpan.metacpan.org/authors/id/"
[ -z "$_F_perl_no_url" ] && url="http://cpan.org/"
[ -z "$_F_archive_name" ] && _F_archive_name="$_F_perl_sourcename"
[ -z "$_F_perl_no_up2date" ] && up2date="Flastarchive https://fastapi.metacpan.org/v1/download_url/${_F_perl_name//-/::} $_F_perl_ext"
[ -z "$_F_perl_no_source" ] && source=($(curl -s https://fastapi.metacpan.org/v1/download_url/${_F_perl_name//-/::} | jq -r '.download_url'))

###
# == OVERWRITTEN VARIABLES
# * _F_cd_path (if not set)
# * pkgname
# * pkgrel (if not set)
# * depends()
# * makedepends()
# * groups()
# * archs()
###
[ -z "$_F_cd_path" ] && _F_cd_path="$_F_perl_sourcename-$pkgver"
pkgname="perl-`echo $_F_perl_name|tr [A-Z] [a-z]`"
[ -z "$pkgrel" ] && pkgrel=1
depends+=('perl>=5.42.0')
[ -z "$groups" ] && groups=('devel-extra')
[ -z "$archs" ] && archs=('x86_64')
makedepends+=('jq')

###
# == PROVIDED FUNCTIONS
# * Fbuild_perl(): improves build() to make use of these functions
###
Fbuild_perl()
{
	Fcd $_F_cd_path
	Fbuild
	Frm /usr/lib/perl5/current
}

###
# * build() just calls Fbuild_perl()
###
build() {
	Fbuild_perl
}
