aboutsummaryrefslogtreecommitdiff
path: root/Mock/IRC.pm
blob: 5c62754568707926aac6d868b86f18e30cb7d8aa (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package Mock::IRC;

use strict;
use warnings;
use Switch;

use fields qw/_joined_channels _nick_name/;

sub new {
	my Mock::IRC $self = shift;
	unless ($self) {
		$self = fields::new($self);
		$self->{_nick_name} = "";
		$self->{_joined_channels} = [];
	}

	bless {}, $self;
}

###############################################################################
# Methods used by code/plugins under test
sub yield {
	my ($self, $event, @data) = @_;
	switch($event) {
		case "join" {
			my $channel = $data[0];
			unless (grep {$_ eq $channel} @{$self->{_joined_channels}}) {
				push @{$self->{_joined_channels}}, $channel;
			}
		}
		case "part" {
			# FIXME supports multi args?
			my $channel = $data[0];
			@{$self->{_joined_channels}} = grep {$_ ne $channel} @{$self->{_joined_channels}};
		}
		case "nick" {
			($self->{_nick_name}) = @data;
		}
		else {
			die "Unsupported event type: $event\n";
		}
	}
}

sub nick_name {
	my ($self) = @_;
	return $self->{_nick_name};
}


###############################################################################
# Methods used test-side follow
sub idalius_get_channels {
	my ($self) = @_;
	return @{$self->{_joined_channels}};
}

sub idalius_is_joined_to {
	my ($self, $channel) = @_;
	return grep {$_ eq $channel} @{$self->{_joined_channels}};
}
1;