XMPP/IM/Delayed.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« XMPP/IM/Account.pm ↑ Summary XMPP/IM/Presence.pm »
1 package AnyEvent::XMPP::IM::Delayed;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 0 ▶use AnyEvent::XMPP::Util;
Subroutine BEGIN: called CC=1 SCAR=2.6
4 use AnyEvent::XMPP::IM::Message;
5  
6 =head1 NAME
7  
8 AnyEvent::XMPP::IM::Delayed - A delayed "XML" stanza
9  
10 =head1 SYNOPSIS
11  
12 =head1 DESCRIPTION
13  
14 This module handles the delayed fields of stanzas and is a superclass of
15 L<AnyEvent::XMPP::IM::Message> and L<AnyEvent::XMPP::IM::Presence>.
16  
17 =head1 METHODS
18  
19 =over 4
20  
21 =item B<new>
22  
23 The constructor takes no arguments and makes just a new object of this class.
24  
25 =cut
26  
27 sub new {
28 my $this = shift;
29 my $class = ref($this) || $this;
30 bless { @_ }, $class
31 }
32  
33 =item B<xml_node ()>
34  
35 Returns the L<AnyEvent::XMPP::Node> object for this stream error.
36  
37 =cut
38  
39 sub xml_node {
40 $_[0]->{node}
41 }
42  
43  
44 =item B<fetch_delay_from_node ($node)>
45  
46 C<$node> must be a L<AnyEvent::XMPP::Node>. This method will try to
47 fetch the delay information from the C<$node>. It will look in the lists
48 of child nodes for the delay elements and set it's values from there.
49  
50 =cut
51  
52 sub fetch_delay_from_node {
53 my ($self, $node) = @_;
54 my ($delay) = $node->find_all ([qw/x_delay x/]);
55 my ($newdelay) = $node->find_all ([qw/delay delay/]);
56  
57 $delay = $newdelay if $newdelay;
58  
59 if ($delay) {
60 $self->{delay}->{from} = $delay->attr ('from');
61 $self->{delay}->{stamp} = $delay->attr ('stamp');
62 $self->{delay}->{reason} = $delay->text;
63 } else {
64 delete $self->{delay}
65 }
66 }
67  
68 =item B<delay_from>
69  
70 This method returns either the original source of a maybe delayed
71 stanza. It's the JID of the original entity that sent the stanza.
72  
73 This method returns undef if this stanza was not delayed.
74  
75 And this method returns undef if this stanza had no details about
76 who sent the message in the first place.
77  
78 To find out whether this stanza was delayed use the C<delay_stamp>
79 method.
80  
81 =cut
82  
83 sub delay_from {
84 my ($self) = @_;
85 return unless exists $self->{delay};
86 $self->{delay}->{from}
87 }
88  
89 =item B<delay_stamp>
90  
91 This method returns the timestamp in XMPP format which can be fed
92 to the C<from_xmpp_datetime> function documented in L<AnyEvent::XMPP::Util>.
93  
94 (Please note that this might be a newstyle XEP-0087 timestamp or
95 old style legacy timestamp)
96  
97 If the stanza was not delayed this method returns undef.
98  
99 =cut
100  
101 sub delay_stamp {
102 my ($self) = @_;
103 return unless exists $self->{delay};
104 $self->{delay}->{stamp}
105 }
106  
107 =item B<delay_reason>
108  
109 This method might return a human readable string containing the reason
110 why the stanza was delayed.
111  
112 Will be undef if stanza contained no delay.
113  
114 =cut
115  
116 sub delay_reason {
117 my ($self) = @_;
118 return unless exists $self->{delay};
119 $self->{delay}->{reason}
120 }
121  
122 =item B<is_delayed>
123  
124 If this method returns a true value then this stanza was delayed.
125 Otherwise it returns undef.
126  
127 =cut
128  
129 sub is_delayed {
130 my ($self) = @_;
131 $self->{delay}
132 }
133  
134 =back
135  
136 =head1 AUTHOR
137  
138 Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >>
139  
140 =head1 COPYRIGHT & LICENSE
141  
142 Copyright 2007, 2008 Robin Redeker, all rights reserved.
143  
144 This program is free software; you can redistribute it and/or modify it
145 under the same terms as Perl itself.
146  
147 =cut
148  
149 1;
« XMPP/IM/Account.pm ↑ Summary XMPP/IM/Presence.pm »