comparison interps/clc-intercal/CLC-INTERCAL-Base-1.-94.-2/INTERCAL/Exporter.pm @ 996:859f9b4339e6

<Gregor> tar xf egobot.tar.xz
author HackBot
date Sun, 09 Dec 2012 19:30:08 +0000
parents
children
comparison
equal deleted inserted replaced
995:6883f5911eb7 996:859f9b4339e6
1 package Language::INTERCAL::Exporter;
2
3 # Like the standard Exporter, but understand INTERCAL (per)version numbers
4
5 # This file is part of CLC-INTERCAL
6
7 # Copyright (c) 2006-2008 Claudio Calvelli, all rights reserved.
8
9 # CLC-INTERCAL is copyrighted software. However, permission to use, modify,
10 # and distribute it is granted provided that the conditions set out in the
11 # licence agreement are met. See files README and COPYING in the distribution.
12
13 use strict;
14 use vars qw($VERSION $PERVERSION);
15 ($VERSION) = ($PERVERSION = "CLC-INTERCAL/Base INTERCAL/Exporter.pm 1.-94.-2") =~ /\s(\S+)$/;
16
17 use Carp;
18 require Exporter;
19 use vars qw(@EXPORT @EXPORT_OK);
20 @EXPORT = qw(import);
21 @EXPORT_OK = qw(is_intercal_number import require_version compare_version);
22
23 sub is_intercal_number {
24 @_ == 1 or croak "Usage: is_intercal_number(STRING)";
25 my ($s) = @_;
26 $s =~ /^-?\d+(?:\.-?\d+)*$/;
27 }
28
29 sub import {
30 my $package = shift;
31 if (@_ && Language::INTERCAL::Exporter::is_intercal_number($_[0])) {
32 Language::INTERCAL::Exporter::require_version($package, shift);
33 }
34 unshift @_, $package;
35 goto &Exporter::import;
36 }
37
38 sub require_version {
39 my ($package, $required) = @_;
40 $package = caller if ! defined $package;
41 no strict 'refs';
42 my $provided = ((${"${package}::PERVERSION"} || '0') =~ /\s(\S+$)/)[0];
43 compare_version($required, $provided) <= 0
44 or croak "$package perversion $provided is too old (required $required)";
45 }
46
47 sub compare_version {
48 @_ == 2 or croak "Usage: compare_version(NUM, NUM)";
49 my ($a, $b) = @_;
50 my @a = split(/\./, $a);
51 my @b = split(/\./, $b);
52 while (@a || @b) {
53 $a = @a ? shift @a : 0;
54 $b = @b ? shift @b : 0;
55 return -1 if $a < $b;
56 return 1 if $a > $b;
57 }
58 0;
59 }
60
61 1;