From: Rafael Kitover Date: Wed, 7 Jul 2010 13:56:52 +0000 (-0400) Subject: fix DOS line ends in table/column comments for Pg X-Git-Tag: 0.07001~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fd97abca561aa48cbcc959417687bf9b36bc9862;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix DOS line ends in table/column comments for Pg --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 85b09f3..ede47bd 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -1797,12 +1797,10 @@ sub _make_pod { my ($table) = @_; my $pcm = $self->pod_comment_mode; my ($comment, $comment_overflows, $comment_in_name, $comment_in_desc); - if ( $self->can('_table_comment') ) { - $comment = $self->_table_comment($table); - $comment_overflows = ($comment and length $comment > $self->pod_comment_spillover_length); - $comment_in_name = ($pcm eq 'name' or ($pcm eq 'auto' and !$comment_overflows)); - $comment_in_desc = ($pcm eq 'description' or ($pcm eq 'auto' and $comment_overflows)); - } + $comment = $self->__table_comment($table); + $comment_overflows = ($comment and length $comment > $self->pod_comment_spillover_length); + $comment_in_name = ($pcm eq 'name' or ($pcm eq 'auto' and !$comment_overflows)); + $comment_in_desc = ($pcm eq 'description' or ($pcm eq 'auto' and $comment_overflows)); $self->_pod( $class, "=head1 NAME" ); my $table_descr = $class; $table_descr .= " - " . $comment if $comment and $comment_in_name; @@ -1840,9 +1838,7 @@ sub _make_pod { } sort keys %$attrs, ); - if( $self->can('_column_comment') - and my $comment = $self->_column_comment( $self->{_class2table}{$class}, $col_counter) - ) { + if (my $comment = $self->__column_comment($self->{_class2table}{$class}, $col_counter)) { $self->_pod( $class, $comment ); } } @@ -1858,6 +1854,36 @@ sub _make_pod { } } +sub _filter_comment { + my ($self, $txt) = @_; + + $txt = '' if not defined $txt; + + $txt =~ s/(?:\015?\012|\015\012?)/\n/g; + + return $txt; +} + +sub __table_comment { + my $self = shift; + + if (my $code = $self->can('_table_comment')) { + return $self->_filter_comment($self->$code(@_)); + } + + return ''; +} + +sub __column_comment { + my $self = shift; + + if (my $code = $self->can('_column_comment')) { + return $self->_filter_comment($self->$code(@_)); + } + + return ''; +} + # Stores a POD documentation sub _pod { my ($self, $class, $stmt) = @_; diff --git a/t/12pg_common.t b/t/12pg_common.t index 564a20b..bb03601 100644 --- a/t/12pg_common.t +++ b/t/12pg_common.t @@ -118,11 +118,11 @@ my $tester = dbixcsl_common_tests->new( value VARCHAR(100) ) }, - q{ - COMMENT ON TABLE pg_loader_test1 IS 'The Table' + qq{ + COMMENT ON TABLE pg_loader_test1 IS 'The\15\12Table' }, - q{ - COMMENT ON COLUMN pg_loader_test1.value IS 'The Column' + qq{ + COMMENT ON COLUMN pg_loader_test1.value IS 'The\15\12Column' }, q{ CREATE TABLE pg_loader_test2 ( @@ -144,10 +144,10 @@ my $tester = dbixcsl_common_tests->new( my $code = slurp $filename; - like $code, qr/^=head1 NAME\n\n^$class - The Table\n\n^=cut\n/m, + like $code, qr/^=head1 NAME\n\n^$class - The\nTable\n\n^=cut\n/m, 'table comment'; - like $code, qr/^=head2 value\n\n(.+:.+\n)+\nThe Column\n\n/m, + like $code, qr/^=head2 value\n\n(.+:.+\n)+\nThe\nColumn\n\n/m, 'column comment and attrs'; $class = $classes->{pg_loader_test2};