undef
lima1
12 years ago
0 | 0 | Revision history for LaTeX-Table |
1 | 1 | |
2 | 1.1 Mon Oct 25 2011 | |
2 | 1.1 Tue Feb 21 2012 | |
3 | 3 | - Removed version dependency |
4 | - Allowed undef values in data and header (thanks Dan, closes #75203) | |
4 | 5 | |
5 | 6 | 1.0.6 Mon Oct 25 2010 |
6 | 7 | - eor option (thanks Jens) |
87 | 87 | has 'resizebox' => ( is => 'rw', isa => 'ArrayRef[Str]' ); |
88 | 88 | has 'columns_like_header' => ( is => 'rw', isa => 'ArrayRef[Int]' ); |
89 | 89 | has 'header' => |
90 | ( is => 'rw', isa => 'ArrayRef[ArrayRef[Value]]', default => sub { [] } ); | |
90 | ( is => 'rw', isa => 'ArrayRef[ArrayRef]', default => sub { [] } ); | |
91 | 91 | has 'data' => |
92 | ( is => 'rw', isa => 'ArrayRef[ArrayRef[Value]]', default => sub { [] } ); | |
92 | ( is => 'rw', isa => 'ArrayRef[ArrayRef]', default => sub { [] } ); | |
93 | 93 | has 'predef_themes' => |
94 | 94 | ( is => 'rw', isa => 'HashRef[HashRef]', default => sub { {} } ); |
95 | 95 | has 'custom_themes' => |
248 | 248 | my $i = 0; |
249 | 249 | COL: |
250 | 250 | for my $col ( @{$row} ) { |
251 | next COL if $col =~ $strategy->{MISSING_VALUE}; | |
251 | next COL if !defined $col || $col =~ $strategy->{MISSING_VALUE}; | |
252 | 252 | |
253 | 253 | for my $coltype (@coltypes) { |
254 | 254 | if ( $col =~ $strategy->{$coltype} ) { |
534 | 534 | |
535 | 535 | sub _get_mc_def { |
536 | 536 | my ( $self, $value ) = @_; |
537 | return { value => undef } if (!defined $value); | |
537 | 538 | return $value =~ m{ \A (.*)\:(\d+)([clr]) \s* \z }xms |
538 | 539 | ? { |
539 | 540 | value => $1, |
0 | use Test::More tests => 21; | |
0 | use Test::More tests => 22; | |
1 | 1 | use Test::NoWarnings; |
2 | 2 | |
3 | 3 | use LaTeX::Table; |
676 | 676 | 'theme with colordef and resizebox' |
677 | 677 | ) || diag $output; |
678 | 678 | |
679 | ||
679 | $test_header | |
680 | = [ [ 'Name', 'Beers:2c' ], [ '', 'before 4pm', 'after 4pm' ] ]; | |
681 | $test_data = [ | |
682 | [ 'Lisa', '0', '0' ], | |
683 | [ 'Marge', '0', '1' ], | |
684 | [ 'Wiggum', '0', '5' ], | |
685 | [ 'Otto', '1', '3' ], | |
686 | [ 'Homer', '2', '6' ], | |
687 | [ 'Barney', '8', undef ], | |
688 | ]; | |
689 | ||
690 | $table = LaTeX::Table->new( | |
691 | { | |
692 | environment => 0, | |
693 | header => $test_header, | |
694 | data => $test_data, | |
695 | callback => sub { | |
696 | my ( $row, $col, $value, $is_header ) = @_; | |
697 | if (!defined $value) { | |
698 | $value = 'NA'; | |
699 | } | |
700 | return $value; | |
701 | } | |
702 | } | |
703 | ); | |
704 | ||
705 | $expected_output = <<'EOT' | |
706 | \begin{tabular}{lrr} | |
707 | \toprule | |
708 | Name & \multicolumn{2}{c}{Beers} \\ | |
709 | & before 4pm & after 4pm \\ | |
710 | \midrule | |
711 | Lisa & 0 & 0 \\ | |
712 | Marge & 0 & 1 \\ | |
713 | Wiggum & 0 & 5 \\ | |
714 | Otto & 1 & 3 \\ | |
715 | Homer & 2 & 6 \\ | |
716 | Barney & 8 & NA \\ | |
717 | \bottomrule | |
718 | \end{tabular} | |
719 | EOT | |
720 | ; | |
721 | ||
722 | ||
723 | $output = $table->generate_string(); | |
724 | ||
725 | is_deeply( | |
726 | [ split( "\n", $output ) ], | |
727 | [ split( "\n", $expected_output ) ], | |
728 | 'undefined columns' | |
729 | ) || diag $output; |
0 | use Test::More tests => 35; | |
0 | use Test::More tests => 33; | |
1 | 1 | use Test::NoWarnings; |
2 | 2 | |
3 | 3 | use LaTeX::Table; |
109 | 109 | 'header[0] is not an array reference' |
110 | 110 | ) || diag $EVAL_ERROR; |
111 | 111 | |
112 | eval { $table->set_header( [ [ 'A', ['B'] ] ] ); }; | |
113 | like( $EVAL_ERROR, qr{Attribute \(header\)}, 'header[0][1] is not a scalar' ) | |
114 | || diag $EVAL_ERROR; | |
115 | ||
116 | 112 | # data tests |
117 | 113 | eval { |
118 | 114 | $table = LaTeX::Table->new( |
130 | 126 | qr{Attribute \(data\)}, |
131 | 127 | 'data[1] is not an array reference' |
132 | 128 | ) || diag $EVAL_ERROR; |
133 | ||
134 | eval { $table->set_data( [ [ 'A', 'B' ], [ 'A', undef ] ] ); }; | |
135 | like( $EVAL_ERROR, qr{Attribute \(data\)}, 'undef value' ) | |
136 | || diag $EVAL_ERROR; | |
137 | 129 | |
138 | 130 | $table->set_data($data); |
139 | 131 | eval { $table->set_coldef_strategy(1); }; |