cvs commit: p5ee/App-Widget/lib/App/SessionObject Content.pm

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     05/10/27 13:25:07

  Added:       App-Widget/lib/App/SessionObject Content.pm
  Log:
  new
  
  Revision  Changes    Path
  1.1                  p5ee/App-Widget/lib/App/SessionObject/Content.pm
  
  Index: Content.pm
  ===================================================================
  
  ######################################################################
  ## $Id: Content.pm,v 1.1 2005/10/27 20:25:07 spadkins Exp $
  ######################################################################
  
  package App::SessionObject::Content;
  $VERSION = do { my @r=(q$Revision: 1.1 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  
  use App::SessionObject;
  @ISA = ( "App::SessionObject" );
  
  use strict;
  
  =head1 NAME
  
  App::SessionObject::Content - an chunk of binary content representing data to be returned to a browser instead of the HTML content that gets returned by an App::Widget (i.e. Excel, PDF, CSV, etc.)
  
  =head1 SYNOPSIS
  
     use App::SessionObject::Content;
  
  =cut
  
  #############################################################################
  # PUBLIC METHODS
  #############################################################################
  
  =head1 Public Methods:
  
  =cut
  
  #############################################################################
  # Method: content()
  #############################################################################
  
  =head2 content()
  
      * Signature: $content = $self->content();
      * Param:     void
      * Return:    $content   any
      * Throws:    App::Exception
      * Since:     0.01
  
      $content = $so->content();
      if (ref($content)) {
          App::Reference->print($content);
          print "\n";
      }
      else {
          print $content, "\n";
      }
  
  =cut
  
  sub content {
      &App::sub_entry if ($App::trace);
      my $self = shift;
      my $contentref = $self->{content};
      if (!$contentref) {
          my $content = "";
          $contentref = \$content;
      }
      elsif (!ref($contentref)) {
          $contentref = \$contentref;
      }
      elsif (ref($contentref) ne "SCALAR") {
          my $content = "";
          $contentref = \$content;
      }
      &App::sub_exit($$contentref) if ($App::trace);
      return($$contentref);
  }
  
  #############################################################################
  # content_type()
  #############################################################################
  
  =head2 content_type()
  
      * Signature: $content_type = $service->content_type();
      * Param:     void
      * Return:    $content_type   string
      * Throws:    App::Exception
      * Since:     0.01
  
      Sample Usage:
  
      $content_type = $service->content_type();
  
  =cut
  
  my %content_type = (
      html => "text/html",
      txt  => "text/plain",
      pdf  => "application/pdf",
      xls  => "application/vnd.ms-excel",
      xml  => "application/xml",
      csv  => "application/octet-stream\nContent-disposition: attachment; filename=\"data.csv\"",
      bin  => "application/octet-stream",
  );
  
  sub content_type {
      &App::sub_entry if ($App::trace);
      my $type = $self->{type} || "html";
      my $content_type = $content_type{$type};
      if (!$content_type) {
          $content_type = $content_type{bin};
      }
      &App::sub_exit($content_type) if ($App::trace);
      return($content_type);
  }
  
  1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.