File: VerbCall.pm

package info (click to toggle)
perlmoo 0.045
  • links: PTS
  • area: main
  • in suites: slink
  • size: 404 kB
  • ctags: 242
  • sloc: perl: 5,211; makefile: 111; sh: 77
file content (83 lines) | stat: -rw-r--r-- 1,378 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# This bbundles up all the data a verb needs to know when it
# is called.

package VerbCall;
use Utils;
use strict;
use vars qw($AUTOLOAD);

sub new {
	my $proto=shift;
	my $class = ref($proto) || $proto;
	my $this = {};
	
	$this->{'caller'} = shift; # caller is a reserved word
	$this->{object} = shift;
	$this->{direct_object} = shift;
	$this->{indirect_object} = shift;
	$this->{command} = shift;
	@{$this->{words}} = @_;
	
	bless($this, $class);
	return $this;
}

# Set/get a word as it was entered by the user.
# Type can be any of verb, direct_object, preposition, or indirect_object.
sub word {
	my $this=shift;
	my $type=shift;

	my $i;
	if ($type eq 'verb') {
		$i=0;
	}
	elsif ($type eq 'direct_object') {
		$i=1;
	}
	elsif ($type eq 'preposition') {
		$i=2;
	}
	elsif ($type eq 'indirect_object') {
		$i=3;
	}
	
	if (! defined($i)) {
		Utils::Log("notice","Unknown word specifier, $type");
	}

	if (@_) {
		return $this->{words}[$i]=shift;
	}
	else {
		return $this->{words}[$i];
	}
}

# Need to handle this specially so an array can be passed in.
sub words {
	my $this=shift;

	if (@_) {
		return @{$this->{words}} = @_;
	}
	else {
		return @{$this->{words}};
	}
}

sub AUTOLOAD {
	my $this=shift;
	
	my $name = $AUTOLOAD;
	$name =~ s/.*://; # strip fully-qualified portion
	
	if (@_) {
		return $this->{$name} = shift;
	}
	else {
		return $this->{$name};
	}	
}

1;