Net::Jabber::Message - Jabber Message Module
Net::Jabber::Message is a companion to the Net::Jabber module. It provides the user a simple interface to set and retrieve all parts of a Jabber Message.
To initialize the Message with a Jabber <message/> you must pass it the XML::Parser Tree array. For example: my $message = new Net::Jabber::Message(@tree); There has been a change from the old way of handling the callbacks. You no longer have to do the above, a Net::Jabber::Message object is passed to the callback function for the message: use Net::Jabber; sub message { my ($Mess) = @_; . . . } You now have access to all of the retrieval functions available. To create a new message to send to the server: use Net::Jabber; $Mess = new Net::Jabber::Message(); Now you can call the creation functions below to populate the tag before sending it. For more information about the array format being passed to the CallBack please read the Net::Jabber::Client documentation.
$to = $Mess->GetTo(); $toJID = $Mess->GetTo("jid"); $from = $Mess->GetFrom(); $fromJID = $Mess->GetFrom("jid"); $resource = $Mess->GetResource(); $type = $Mess->GetType(); $subject = $Mess->GetSubject(); $body = $Mess->GetBody(); @body = $Mess->GetBody("full"); $thread = $Mess->GetThread(); $priority = $Mess->GetPriority(); $error = $Mess->GetError(); $errCode = $Mess->GetErrorCode(); @xTags = $Mess->GetX(); @xTags = $Mess->GetX("my:namespace"); @xTrees = $Mess->GetXTrees(); @xTrees = $Mess->GetXTrees("my:namespace"); $str = $Mess->GetXML(); @message = $Mess->GetTree(); $date = $Mess->GetTimeStamp();
$Mess->SetMessage(TO=>"bob\@jabber.org/Working Bob", Subject=>"Lunch", BoDy=>"Let's go grab some lunch!", priority=>100); $Mess->SetTo("test\@jabber.org"); $Mess->SetFrom("me\@jabber.org"); $Mess->SetType("groupchat"); $Mess->SetSubject("This is a test"); $Mess->SetBody("This is a test of the emergency broadcast system..."); $Mess->SetThread("AE912B3"); $Mess->SetPriority(1); $Mess->SetMessage(to=>"bob\@jabber.org", errorcode=>403, error=>"Permission Denied"); $Mess->SetErrorCode(403); $Mess->SetError("Permission Denied"); $X = $Mess->NewX("jabber:x:delay"); $X = $Mess->NewX("my:namespace"); $X = $Mess->NewX(Net::Jabber::X::XXXXX); $Reply = $Mess->Reply(); $Reply = $Mess->Reply(template=>"transport-filter");
$test = $Mess->DefinedTo(); $test = $Mess->DefinedFrom(); $test = $Mess->DefinedType(); $test = $Mess->DefinedSubject(); $test = $Mess->DefinedBody(); $test = $Mess->DefinedThread(); $test = $Mess->DefinedPriority(); $test = $Mess->DefinedErrorCode(); $test = $Mess->DefinedError();
GetTo() - returns either a string with the Jabber Identifier, GetTo("jid") or a Net::Jabber::JID object for the person who is going to receive the <message/>. To get the JID object set the string to "jid", otherwise leave blank for the text string. GetFrom() - returns either a string with the Jabber Identifier, GetFrom("jid") or a Net::Jabber::JID object for the person who sent the <message/>. To get the JID object set the string to "jid", otherwise leave blank for the text string. GetResource() - returns a string with the Jabber Resource of the person who sent the <message/>. GetType() - returns a string with the type <message/> this is. GetSubject() - returns a string with the subject of the <message/>. GetBody(string) - returns the data in the <body/> tag depending on the value of the string passed to it. The string represents the mark up level to return. none returns a string with just the text of the <body/> (default) full returns an XML::Paser::Tree with everything in the <body/> GetThread() - returns a string that represents the thread this <message/> belongs to. GetPriority() - returns an integer with the priority of the <message/>. GetError() - returns a string with the data of the <error/> tag. GetErrorCode() - returns a string with the code of the <error/> tag. GetX(string) - returns an array of Net::Jabber::X objects. The string can either be empty or the XML Namespace you are looking for. If empty then GetX returns every <x/> tag in the <message/>. If an XML Namespace is sent then GetX returns every <x/> tag with that Namespace. GetXTrees(string) - returns an array of XML::Parser::Tree objects. The string can either be empty or the XML Namespace you are looking for. If empty then GetXTrees returns every <x/> tag in the <message/>. If an XML Namespace is sent then GetXTrees returns every <x/> tag with that Namespace. GetXML() - returns the XML string that represents the <message/>. This is used by the Send() function in Client.pm to send this object as a Jabber Message. GetTree() - returns an array that contains the <message/> tag in XML::Parser Tree format. GetTimeStamp() - returns a string that represents the time this message object was created (and probably received) for sending to the client. If there is an <x/> delay tag then that time is used to show when the message was sent.
SetMessage(to=>string|JID, - set multiple fields in the <message/> from=>string|JID, at one time. This is a cumulative type=>string, and over writing action. If you set subject=>string, the "to" attribute twice, the second body=>string, setting is what is used. If you set thread=>string, the subject, and then set the body priority=>integer, then both will be in the <message/> errorcode=>string, tag. For valid settings read the error=>string) specific Set functions below. SetTo(string) - sets the to attribute. You can either pass a string SetTo(JID) or a JID object. They must be valid Jabber Identifiers or the server will return an error message. (ie. jabber:bob@jabber.org/Silent Bob, etc...) SetFrom(string) - sets the from attribute. You can either pass a string SetFrom(JID) or a JID object. They must be valid Jabber Identifiers or the server will return an error message. (ie. jabber:bob@jabber.org/Silent Bob, etc...) SetType(string) - sets the type attribute. Valid settings are: chat defines a chat style message error defines an error message groupchat defines a chatroom message normal defines a normal message (default) SetSubject(string) - sets the subject of the <message/>. SetBody(string) - sets the body of the <message/>. SetThread(string) - sets the thread of the <message/>. You should copy this out of the message being replied to so that the thread is maintained. SetPriority(integer) - sets the priority of this <message/>. The higher the priority the more likely the client will deliver the message, even if the user has specified no messages. SetErrorCode(string) - sets the error code of the <message/>. SetError(string) - sets the error string of the <message/>. NewX(string) - creates a new Net::Jabber::X object with the namespace in the string. In order for this function to work with a custom namespace, you must define and register that namespace with the X module. For more information please read the documentation for Net::Jabber::X. Reply(template=>string, - creates a new Message object and replytransport=>string) populates the to/from based on the value of template. The following templates are available: normal: (default) just sets the to/from transport-filter: the transport will send the reply to the address from the to. ie( bob%j.org@transport.j.org would send to bob@j.org) transport-filter-reply: the transport will send the reply to the address from the to. ie( bob%j.org@transport.j.org would send to bob@j.org) and set the from to be sender@replytransport. That way a two way filter can occur.
DefinedTo() - returns 1 if the to attribute is defined in the <message/>, 0 otherwise. DefinedFrom() - returns 1 if the from attribute is defined in the <message/>, 0 otherwise. DefinedType() - returns 1 if the type attribute is defined in the <message/>, 0 otherwise. DefinedSubject() - returns 1 if <subject/> is defined in the <message/>, 0 otherwise. DefinedBody() - returns 1 if <body/> is defined in the <message/>, 0 otherwise. DefinedThread() - returns 1 if <thread/> is defined in the <message/>, 0 otherwise. DefinedPriority() - returns 1 if <priority/> is defined in the <message/>, 0 otherwise. DefinedErrorCode() - returns 1 if <error/> is defined in the <message/>, 0 otherwise. DefinedError() - returns 1 if the code attribute is defined in the <error/>, 0 otherwise.
By Ryan Eatmon in May of 2000 for http://jabber.org..
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Net::Jabber, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Jabber
CPAN shell
perl -MCPAN -e shell install Net::Jabber
For more information on module installation, please visit the detailed CPAN module installation guide.