summaryrefslogtreecommitdiffabout
path: root/lib/SlackBuild/Base.pm
blob: 9710392f7eba4a26d346f753ca70694cebdb02a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package SlackBuild::Base;
use strict;
use warnings;
use Carp;
use parent 'Exporter';
no strict 'refs';

sub import {
    my $pkg = shift;            # package
    my ($package, $filename, $line) = caller;
    foreach my $dfn (@_) {
	if ($dfn =~ m/^(?<attr>[a-zA-Z_][a-zA-Z_0-9]*)
                       (?::(?<flag>.*))?$/x) {
	    my $attribute = $+{attr};
	    my $flag = $+{flag} || 'rw';
	    if ($flag eq 'ro') {
		*{ $package . '::' . $attribute } = sub {
		    my $self = shift;
		    croak "too many arguments for ${package}::$attribute"
			if @_;
		    return $self->{$attribute};
		}
	    } else {
		*{ $package . '::' . $attribute } = sub {
		    my $self = shift;
		    if (@_) {
			croak "too many arguments for ${package}::$attribute"
			    if @_ > 1;
			$self->{$attribute} = shift;
		    }
		    return $self->{$attribute};
		}
	    }
	} else {
	    croak "$filename:$line: bad attribute spec: $dfn"
	}
    }
}

1;

Return to:

Send suggestions and report system problems to the System administrator.