NAME

Catalyst::View::Download::CSV

SYNOPSIS

  # lib/MyApp/View/Download/CSV.pm
  package MyApp::View::Download::CSV;
  use base qw( Catalyst::View::Download::CSV );
  1;

  # lib/MyApp/Controller/SomeController.pm
  sub example_action_1 : Local {
    my ($self, $c) = @_;
  
    # Array reference of array references.
    my $data = [
      ['col 1','col 2','col ...','col N'], # row 1
      ['col 1','col 2','col ...','col N'], # row 2
      ['col 1','col 2','col ...','col N'], # row ...
      ['col 1','col 2','col ...','col N']  # row N
    ];

    # To output your data in comma seperated values just pass your array by reference into the 'csv' key of the stash
    $c->stash->{'csv'} = $data;

    # Finally forward processing to the CSV View
    $c->forward('MyApp::View::Download::CSV');
  }

  # Other ways of storing data
  sub example_action_2 : Local {
    my ($self, $c) = @_;

    # Array of array references
    my @data;

    push(@data,['col 1','col 2','col ...','col N']); # row 1
    push(@data,['col 1','col 2','col ...','col N']); # row 2
    push(@data,['col 1','col 2','col ...','col N']); # row ...
    push(@data,['col 1','col 2','col ...','col N']); # row N

    # OR to produce a single column of data you can simply do the following 
    my @data = (
                'col 1 row 1',
                'col 1 row 2',
                'col 1 row ...',
                'col 1 row N'
               );

    $c->stash->{'csv'} = \@data;

    $c->forward('MyApp::View::Download::CSV');
  }

  # Available Options to produce other types of delimiter seperated output
  sub  example_action_3 : Local {
    my ($self, $c) = @_;

    my $data = [
      ['col 1','col 2','col ...','col N'], # row 1
      ['col 1','col 2','col ...','col N'] # row 2
    ];

    # You can change any of the aspects of a delimiter seperated values format by change the view configuration
    # This is an example of tab seperated values for instance

		$c->view('MyApp::View::Download')->config(
			'stash_key' => 'data',
			'quote_char' => '"',
			'escape_char' => '"',
			'sep_char' => "\t",
			'eol' => "\n",
		);

    $c->stash->{'data'} = $data;
		
		$c->forward('MyApp::View::Download::CSV');
  }

SUBROUTINES

process

This method will be called by Catalyst if it is asked to forward to a component without a specified action.

render

Allows others to use this view for much more fine-grained content generation.

CONFIG

stash_key

Determines the key in the stash this view will look for when attempting to retrieve data to process. If this key isn't found it will then look at the stash as a whole, find any array references and process them.

$c->view('MyApp::View::Download')->config->{'stash_key'} = 'data';
quote_char

Determines what value will be enclosed within if it contains whitespace or the delimiter character. DEFAULT: '"'

$c->view('MyApp::View::Download')->config->{'quote_char'} = '/';
escape_char

Determines what value will be to escape any delimiter's found in a column. DEFAULT: '"'

$c->view('MyApp::View::Download')->config->{'escape_char'} = '/';
sep_char

Determines the separator between columns. DEFAULT: ','

$c->view('MyApp::View::Download')->config->{'sep_char'} = '|';
eol

Any characters defined in eol will be placed at the end of a row. DEFAULT: '\n'

$c->view('MyApp::View::Download')->config->{'eol'} = '\0';

AUTHOR

Travis Chase, <gaudeon at cpan.org>

SEE ALSO

Catalyst Catalyst::View Catalyst::View::Download Text::CSV

CONTRIBUTORS

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2008 Travis Chase, all rights reserved.

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