Net-Jabber

 view release on metacpan or  search on metacpan

lib/Net/Jabber/Log.pm  view on Meta::CPAN


    use Net::Jabber;

    sub log {
      my ($Log) = @_;
      .
      .
      .
    }

  You now have access to all of the retrieval functions available.

  To create a new log to send to the server:

    use Net::Jabber;

    $Log = new Net::Jabber::Log();

  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.

=head2 Retrieval functions

    $from       = $Log->GetFrom();
    $fromJID    = $Log->GetFrom("jid");
    $type       = $Log->GetType();
    $data       = $Log->GetData();

    $str        = $Log->GetXML();
    @log        = $Log->GetTree();

=head2 Creation functions

    $Log->SetLog(type=>"error",
		 from=>"users.jabber.org",
		 data=>"The moon is full... I can't run anymore.");
    $Log->SetFrom("foo.jabber.org");
    $Log->SetType("warn");
    $Log->SetData("I can't find a config file.  Using defaults.");

=head2 Test functions

    $test = $Log->DefinedFrom();
    $test = $Log->DefinedType();

=head1 METHODS

=head2 Retrieval functions

  GetFrom()      -  returns either a string with the Jabber Identifier,
  GetFrom("jid")    or a Net::Jabber::JID object for the person who
                    sent the <log/>.  To get the JID object set 
                    the string to "jid", otherwise leave blank for the 
                    text string.

  GetType() - returns a string with the type <log/> this is.

  GetData() - returns a string with the cdata of the <log/>.

  GetXML() - returns the XML string that represents the <log/>.
             This is used by the Send() function in Client.pm to send
             this object as a Jabber Log.

  GetTree() - returns an array that contains the <log/> tag
              in XML::Parser Tree format.

=head2 Creation functions

  SetLog(from=>string|JID, - set multiple fields in the <log/>
         type=>string,       at one time.  This is a cumulative
         data=>string)       and over writing action.  If you set
                             the "from" attribute twice, the second
                             setting is what is used.  If you set
                             the type, and then set the data
                             then both will be in the <log/>
                             tag.  For valid settings read the
                             specific Set functions below.

  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 log.
                    (ie.  jabber:bob@jabber.org/Silent Bob, etc...)

  SetType(string) - sets the type attribute.  Valid settings are:

                    notice     general logging
                    warn       warning
                    alert      critical error (can still run but not 
                               correctly)
                    error      fatal error (cannot run anymore)

  SetData(string) - sets the cdata of the <log/>.

=head2 Test functions

  DefinedFrom() - returns 1 if the from attribute is defined in the 
                  <log/>, 0 otherwise.

  DefinedType() - returns 1 if the type attribute is defined in the 
                  <log/>, 0 otherwise.

=head1 AUTHOR

By Ryan Eatmon in May of 2000 for http://jabber.org..

=head1 COPYRIGHT

This module is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

require 5.003;
use strict;
use Carp;
use vars qw($VERSION $AUTOLOAD %FUNCTIONS);

$VERSION = "2.0";

sub new
{
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self = { };
    
    $self->{VERSION} = $VERSION;
    $self->{TIMESTAMP} = &Net::Jabber::GetTimeStamp("local");

    bless($self, $proto);

    $self->{DEBUG} = new Net::Jabber::Debug(usedefault=>1,
                                                    header=>"NJ::Log");

    if ("@_" ne (""))
    {
        if (ref($_[0]) eq "Net::Jabber::Log")
        {
            return $_[0];
        }
        else
        {
            my @temp = @_;
            $self->{LOG} = \@temp;
        }
    }
    else
    {
        $self->{LOG} = [ "log" , [{}]];
    }

    return $self;
}



( run in 1.324 second using v1.01-cache-2.11-cpan-39bf76dae61 )