1package DJabberd::Roster; 2use strict; 3use warnings; 4 5sub new { 6 my $class = shift; 7 my $self = bless {}, $class; 8 9 $self->{items} = []; 10 $self->{cache_gets} = 0; # times retrieved from cache 11 12 return $self; 13} 14 15sub inc_cache_gets { 16 return ++$_[0]->{cache_gets}; 17} 18 19sub cache_gets { 20 return $_[0]->{cache_gets}; 21} 22 23sub add { 24 my $self = shift; 25 my $item = shift; 26 die unless $item && $item->isa("DJabberd::RosterItem"); 27 push @{$self->{items}}, $item; 28} 29 30sub items { 31 my $self = shift; 32 return @{ $self->{items} }; 33} 34 35sub from_items { 36 my $self = shift; 37 return grep { $_->subscription->sub_from } @{ $self->{items} }; 38} 39 40sub to_items { 41 my $self = shift; 42 return grep { $_->subscription->sub_to } @{ $self->{items} }; 43} 44 45sub as_xml { 46 my $self = shift; 47 my $xml = "<query xmlns='jabber:iq:roster'>"; 48 foreach my $it (@{ $self->{items} }) { 49 next if $it->subscription->is_none_pending_in; 50 $xml .= $it->as_xml; 51 } 52 $xml .= "</query>"; 53 return $xml; 54} 55 561; 57