Show
Ignore:
Timestamp:
10/23/08 18:13:21 (6 years ago)
Author:
lopnor
Message:

halfway

Location:
lang/perl/Catalyst-View-Spreadsheet-WriteExcel/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Catalyst-View-Spreadsheet-WriteExcel/trunk

    • Property svn:ignore set to
      META.yml
      Makefile
      Makefile.old
      blib
      inc
      pm_to_blib
  • lang/perl/Catalyst-View-Spreadsheet-WriteExcel/trunk/Makefile.PL

    r21966 r21978  
    88 
    99build_requires 'Test::More'; 
     10build_requires 'Spreadsheet::ParseExcel'; 
    1011 
    11 auto_include; 
    1212WriteAll; 
  • lang/perl/Catalyst-View-Spreadsheet-WriteExcel/trunk/lib/Catalyst/View/Spreadsheet/WriteExcel.pm

    r21966 r21978  
    22use strict; 
    33use warnings; 
     4our $VERSION = '0.01'; 
     5use utf8; 
    46 
    57use base qw(Catalyst::View); 
     8use NEXT; 
     9 
    610use Spreadsheet::WriteExcel; 
     11use File::Temp; 
     12use Unicode::String qw(utf8 utf16); 
    713 
    8 our $VERSION = '0.01'; 
     14__PACKAGE__->mk_accessors(qw( expose_stash )); 
    915 
     16sub new { 
     17    my ( $class, $c, $arguments ) = @_; 
     18    my $self = $class->NEXT::new($c); 
     19 
     20    for my $field (keys %{$arguments}) { 
     21        if ($self->can($field)) { 
     22            $self->$field($arguments->{$field}); 
     23        } else { 
     24            $c->log->debug("unknown config parameter '$field'"); 
     25        } 
     26    } 
     27    return $self; 
     28} 
    1029 
    1130sub process { 
    1231    my ( $self, $c ) = @_; 
    13     $c->res->body('hoge'); 
     32    my $file = File::Temp->new; 
     33    my $book = Spreadsheet::WriteExcel->new($file); 
     34    my $sheet = $book->add_worksheet; 
     35#    $sheet->write(0,0, 'abc'); 
     36    $book->close; 
     37    open my $fh, '<', $file->filename; 
     38    my $output = do {local $/; <$fh>}; 
     39    close $fh; 
     40    $c->res->content_type('application/vnd.ms-excel'); 
     41    $c->res->body($output); 
    1442} 
    1543 
  • lang/perl/Catalyst-View-Spreadsheet-WriteExcel/trunk/t/01_server.t

    r21966 r21978  
    11use Test::More tests => 3; 
     2use Spreadsheet::ParseExcel; 
     3use File::Temp; 
    24 
    35use FindBin; 
     
    1113    ok( my $response = request($request), 'Request' ); 
    1214    ok( $response->is_success, 'Response Successful 2xx' ); 
    13     is $response->content, 'hoge'; 
     15    my $file = File::Temp->new(UNLINK => 0, SUFFIX => '.xls'); 
     16    print $file $response->content; 
     17    close $file; 
     18    my $excel = Spreadsheet::ParseExcel->new->Parse($file->filename); 
     19    warn $file->filename; 
     20    use Data::Dumper; 
     21    warn Dumper $excel; 
     22    is $excel->{Worksheet}->[0]->{Cells}[0][0], 'hoge'; 
    1423} 
  • lang/perl/Catalyst-View-Spreadsheet-WriteExcel/trunk/t/lib/TestApp.pm

    r21966 r21978  
    33use warnings; 
    44 
    5 use Catalyst; 
     5use Catalyst qw/-Debug/; 
    66 
    77our $VERSION = '0.01'; 
     
    99        name => 'TestApp', 
    1010        'View::Excel' => { 
    11  
     11            expose_stash => 'sheet', 
    1212        }, 
    1313    }); 
     
    1717sub foo : Global { 
    1818    my ( $self, $c ) = @_; 
     19    $c->stash( 
     20        sheet => [ 
     21            { 
     22                a => 'b', 
     23                c => 'd',  
     24            }, 
     25            { 
     26                a => '1', 
     27                c => '2', 
     28            } 
     29        ] 
     30    ); 
    1931    $c->forward('TestApp::View::Excel'); 
    2032}