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

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     05/10/28 10:18:55

  Modified:    App-Widget/lib/App Widget.pm
  Log:
  added set_alternative_content()
  
  Revision  Changes    Path
  1.8       +54 -4     p5ee/App-Widget/lib/App/Widget.pm
  
  Index: Widget.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Widget/lib/App/Widget.pm,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Widget.pm	9 Aug 2005 19:21:27 -0000	1.7
  +++ Widget.pm	28 Oct 2005 17:18:54 -0000	1.8
  @@ -111,8 +111,8 @@
   sub content {
       &App::sub_entry if ($App::trace);
       my $self = shift;
  -
       my ($html);
  +
       eval {
           $html = $self->html();
       };
  @@ -147,6 +147,13 @@
   EOF
       }
   
  +    if (defined $self->{content}) {
  +        my $content = $self->{content};
  +        $self->{content} = "";
  +        &App::sub_exit($content) if ($App::trace);
  +        return($content);
  +    }
  +
       my ($title, $bodyoptions, $w, $var, $value);
   
       $title = "Widget";
  @@ -240,6 +247,33 @@
   }
   
   #############################################################################
  +# set_alternative_content()
  +#############################################################################
  +
  +=head2 set_alternative_content()
  +
  +    * Signature: $service->set_alternative_content($content, $extension);
  +    * Param:     $content        string
  +    * Param:     $extension      string
  +    * Return:    void
  +    * Throws:    App::Exception
  +    * Since:     0.01
  +
  +    Sample Usage:
  +
  +    $service->set_alternative_content("red,green,blue\n1,2,3\n", "csv");
  +
  +=cut
  +
  +sub set_alternative_content {
  +    &App::sub_entry if ($App::trace);
  +    my ($self, $content, $extension) = @_;
  +    $self->{content}   = $content;
  +    $self->{extension} = $extension;
  +    &App::sub_exit() if ($App::trace);
  +}
  +
  +#############################################################################
   # content_type()
   #############################################################################
   
  @@ -257,9 +291,25 @@
   
   =cut
   
  +my %content_type = (
  +    html => "text/html",
  +    txt  => "text/plain",
  +    pdf  => "application/pdf\nContent-disposition: attachment; filename=\"data.pdf\"",
  +    xls  => "application/vnd.ms-excel\nContent-disposition: attachment; filename=\"data.xls\"",
  +    xml  => "application/xml",
  +    csv  => "application/octet-stream\nContent-disposition: attachment; filename=\"data.csv\"",
  +    bin  => "application/octet-stream\nContent-disposition: attachment; filename=\"data.bin\"",
  +);
  +
   sub content_type {
       &App::sub_entry if ($App::trace);
  -    my $content_type = 'text/html';
  +    my ($self) = @_;
  +    my $extension = $self->{extension} || "html";
  +    delete $self->{extension} if (!defined $self->{content});
  +    my $content_type = $content_type{$extension};
  +    if (!$content_type) {
  +        $content_type = $content_type{bin};
  +    }
       &App::sub_exit($content_type) if ($App::trace);
       return($content_type);
   }
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.