How to detect the version of a installed perl module during portbuild

Matthew Seaman m.seaman at
Wed Jan 4 08:59:31 UTC 2012

On 03/01/2012 23:41, Paul Schmehl wrote:
> This returns the installed package:
> pkg_info -qa | grep "p5-JSON-RPC" | sort | uniq

Woah!  Try it like this:

pkg_info -Ex p5-JSON-RPC

> so maybe you could do something like?
> JSON_VER=`pkg_info -qa | grep "p5-JSON-RPC" | sort | uniq | cut -d'-' -f4`

JSON_VER=$( pkg_info -Ex p5-JSON-RPC | sed -e 's/^.*-//' )

> .if ${JSON_VER} >= 1
>  do this
> .else
>  do this
> .endif

case ${JSON_VER) in

case does a string comparison using standard shell globbing rules --
it's a lot more flexible than trying to do maths on version numbers.

Using perl to generate the version number is also viable as suggested by

perl -MJSON::RPC -le 'print $JSON::RPC::VERSION'

but it strikes me as slightly wasteful to fire up an entire perl
interpreter just to print out the value of one variable.

However, if the object is to create a port that has a BUILD_DEPENDS on
devel/p5-JSON-RPC then you only need to support what is already in the
ports -- and that's version 1.01.  The BUILD_DEPENDS line can enforce that:


Should you have some program that requires JSON::RPC <= 0.96, then
create a p5-JSON-RPC-096 port to provide exactly that.



Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP:     Ramsgate
JID: matthew at               Kent, CT11 9PW

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 267 bytes
Desc: OpenPGP digital signature
Url :

More information about the freebsd-ports mailing list