Net-BEEP-Lite

 view release on metacpan or  search on metacpan

lib/Net/BEEP/Lite/MgmtProfile.pm  view on Meta::CPAN


=item StartData

Data to piggyback with the start channel request.  This is optional.

=item Encoding

Set this to true of the StartData value is base64 encoded.

=back

=cut

sub start_channel_message {
  my $self    = shift;
  my %args    = @_;

  my ($number, $uri, $encoding, $servername, $data);
  # get the optional args
  for (keys %args) {
    my $val = $args{$_};
    /^Channel$/i and do {
      $number = $val;
      next;
    };
    /^URI/i and do {
      $uri = $val;
      next;
    };
    /^encoding$/i and do {
      $encoding = $val;
      next;
    };
    /^server.?name$/i and do {
      $servername = $val;
      next;
    };
    /^start.?data$/i and do {
      $data = $val;
      next;
    };
  }

  croak "start_channel_message(): missing required parameter 'Channel'\n"
    if not $number;
  croak "start_channel_message(): missing required parameter 'URI'\n"
    if not $uri;

  my $start_el = XML::LibXML::Element->new("start");

  $start_el->setAttribute("number", $number);
  $start_el->setAttribute("serverName", $servername) if $servername;

  my $profile_el = XML::LibXML::Element->new("profile");
  $profile_el->setAttribute('uri', $uri);
  $start_el->appendChild($profile_el);

  # FIXME: should be able to pass in a Node or string as data.
  if ($data) {
    if (!ref($data)) {
      my $cdata = XML::LibXML::CDATASection->new($data);
      $profile_el->appendChild($cdata);
    } elsif ($data->isa('XML::LibXML::CDATASection')) {
      $profile_el->appendChild($data);
    }
    $profile_el->setAttribute("encoding", "base64") if $encoding;
  }

  my $msg = $self->_new_mgmt_message(Type    => 'MSG',
				     Content => $start_el->toString());
  $msg;
}

=item send_start_channel_message($session, I<ARGS>)

In addition to the session, the parameters are the same as the named
parameters for the C<start_channel_message> method.  The 'Channel'
parameter may (and usually is) omitted.  This method returns the
channel number requested, and the message itself

=cut

sub send_start_channel_message {
  my $self    = shift;
  my $session = shift;
  my %args    = @_;

  $args{Channel} = $session->_next_channel_number()
    if not $args{Channel};

  $session->{starting_channel_number} = $args{Channel};

  my $msg = $self->start_channel_message(%args);

  $session->send_message($msg);

  ($args{Channel}, $msg);
}

=item close_channel_message($channel_number, [$code, $content, $lang])

This method will return a formatted "<close>" message.  $channel_number
is required.  $code will default to '200'.  $content is optional.
$lang is also optional, and is only meaningful if there is content.

=cut

sub close_channel_message {
  my $self    = shift;
  my $chno    = shift;
  my $code    = shift || 200;
  my $content = shift;
  my $lang    = shift;

  my $close_el = XML::LibXML::Element->new("close");
  $close_el->setAttribute("number", $chno);
  $close_el->setAttribute("code", $code);
  $close_el->setAttribute("xml:lang", $lang) if $lang;
  $close_el->appendText($content) if $content;


  $self->_new_mgmt_message(Type    => 'MSG',



( run in 2.636 seconds using v1.01-cache-2.11-cpan-7fcb06a456a )