# Automatically generated by apkbuild-cpan, template 4
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=perl-mojo-redis
#_pkgreal is used by apkbuild-cpan to find modules at MetaCpan
_pkgreal=Mojo-Redis
pkgver=3.29
pkgrel=0
pkgdesc="Redis driver based on Mojo::IOLoop"
url="https://metacpan.org/release/Mojo-Redis/"
arch="noarch"
license="Artistic-2.0"
depends="perl perl-mojolicious perl-protocol-redis-faster"
checkdepends="perl-test-deep redis"
subpackages="$pkgname-doc"
source="https://cpan.metacpan.org/authors/id/J/JH/JHTHORSEN/Mojo-Redis-$pkgver.tar.gz"
builddir="$srcdir/$_pkgreal-$pkgver"

prepare() {
	default_prepare

	# disable a very flaky test
	rm -v ./t/pubsub.t
}

build() {
	export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
	PERL_MM_USE_DEFAULT=1 perl -I. Makefile.PL \
		INSTALLDIRS=vendor \
		NO_PACKLIST=1 \
		NO_PERLLOCAL=1
	make
}

check() {
	export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
	export TEST_ONLINE="redis://localhost"

	redis-server \
		--dir "$builddir" \
		--loglevel warning \
		--unixsocket "$builddir"/redis.sock &
	local _redispid=$!

	# make sure socket is available before we start running tests
	local _n=100 # wait up to 10 sec
	while ! [ -e "$builddir"/redis.sock ] && [ $_n -gt 0 ]; do
		sleep 0.1s
		# shellcheck disable=SC3039
		let _n="$_n - 1"
	done

	make test || (kill $_redispid && false)
	kill $_redispid
}

package() {
	make DESTDIR="$pkgdir" install
}

sha512sums="
115b0ea8708fff9d4a14dc761dad0f991cf78dbfc9aa19a0a30f5c8914f6e8f153026253e8a97bd30282fdd3272a03e7a61a7c9ee1214187fb62693caffa334d  Mojo-Redis-3.29.tar.gz
"
