r18736 - in /branches/upstream/libtext-csv-perl/current: CSV_XS.pm CSV_XS.xs ChangeLog MANIFEST META.yml Makefile.PL t/76_magic.t

gregoa-guest at users.alioth.debian.org gregoa-guest at users.alioth.debian.org
Thu Apr 17 20:21:10 UTC 2008


Author: gregoa-guest
Date: Thu Apr 17 20:21:09 2008
New Revision: 18736

URL: http://svn.debian.org/wsvn/?sc=1&rev=18736
Log:
[svn-upgrade] Integrating new upstream version, libtext-csv-perl (0.42)

Added:
    branches/upstream/libtext-csv-perl/current/t/76_magic.t
Modified:
    branches/upstream/libtext-csv-perl/current/CSV_XS.pm
    branches/upstream/libtext-csv-perl/current/CSV_XS.xs
    branches/upstream/libtext-csv-perl/current/ChangeLog
    branches/upstream/libtext-csv-perl/current/MANIFEST
    branches/upstream/libtext-csv-perl/current/META.yml
    branches/upstream/libtext-csv-perl/current/Makefile.PL

Modified: branches/upstream/libtext-csv-perl/current/CSV_XS.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libtext-csv-perl/current/CSV_XS.pm?rev=18736&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/CSV_XS.pm (original)
+++ branches/upstream/libtext-csv-perl/current/CSV_XS.pm Thu Apr 17 20:21:09 2008
@@ -30,7 +30,7 @@
 use Carp;
 
 use vars   qw( $VERSION @ISA );
-$VERSION = "0.41";
+$VERSION = "0.42";
 @ISA     = qw( DynaLoader );
 
 sub PV { 0 }
@@ -1130,8 +1130,6 @@
 
 An example for creating CSV files:
 
-  use Text::CSV_XS;
-
   my $csv = Text::CSV_XS->new;
 
   open my $csv_fh, ">", "hello.csv" or die "hello.csv: $!";
@@ -1149,9 +1147,7 @@
       }
   close $csv_fh;
 
-An example for parsing CSV lines:
-
-  use Text::CSV_XS;
+An example for parsing CSV strings:
 
   my $csv = Text::CSV_XS->new ({ keep_meta_info => 1, binary => 1 });
 
@@ -1170,6 +1166,27 @@
       $csv->error_diag ();
       }
 
+Dumping the content of a database ($dbh) table ($tbl) to CSV:
+
+  my $csv = Text::CSV_XS->new ({ binary => 1, eol => $/ });
+  open my $fh, ">", "$tbl.csv" or die "$tbl.csv: $!";
+  my $sth = $dbh->prepare ("select * from $tbl");
+  $sth->execute;
+  $csv->print ($fh, $sth->{NAME_lc});
+  while (my $row = $sth->fetch) {
+      $csv->print ($fh, $row);
+      }
+  close $fh;
+
+Reading a CSV file line by line:
+
+  my $csv = Text::CSV_XS->new ({ binary => 1 });
+  open my $fh, "<", "file.csv" or die "file.csv: $!";
+  while (my $row = $csv->getline ($fh)) {
+      # do something with @$row
+      }
+  close $fh;
+
 =head1 TODO
 
 =over 2

Modified: branches/upstream/libtext-csv-perl/current/CSV_XS.xs
URL: http://svn.debian.org/wsvn/branches/upstream/libtext-csv-perl/current/CSV_XS.xs?rev=18736&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/CSV_XS.xs (original)
+++ branches/upstream/libtext-csv-perl/current/CSV_XS.xs Thu Apr 17 20:21:09 2008
@@ -56,8 +56,9 @@
 
 #define unless(expr)	if (!(expr))
 
-#define _is_arrayref(f) \
-    ( f && SvOK (f) && SvROK (f) && SvTYPE (SvRV (f)) == SVt_PVAV )
+#define _is_arrayref(f) ( f && \
+     (SvROK (f) || (SvRMAGICAL (f) && (mg_get (f), 1) && SvROK (f))) && \
+      SvOK (f) && SvTYPE (SvRV (f)) == SVt_PVAV )
 
 #define CSV_XS_SELF					\
     if (!self || !SvOK (self) || !SvROK (self) ||	\
@@ -1143,7 +1144,7 @@
 
     CSV_XS_SELF;
     unless (_is_arrayref (fields))
-      croak ("Expected fields to be an array ref");
+	croak ("Expected fields to be an array ref");
 
     av = (AV*)SvRV (fields);
 

Modified: branches/upstream/libtext-csv-perl/current/ChangeLog
URL: http://svn.debian.org/wsvn/branches/upstream/libtext-csv-perl/current/ChangeLog?rev=18736&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/ChangeLog (original)
+++ branches/upstream/libtext-csv-perl/current/ChangeLog Thu Apr 17 20:21:09 2008
@@ -1,3 +1,11 @@
+2008-04-16  0.42 - H.Merijn Brand   <h.m.brand at xs4all.nl>
+
+	* Generate META.yml myself. I won't use Build.PL
+	* Array-refs now accept scalars with magic:
+	  $csv->print (*STDOUT, $sth->{NAME_lc});
+	* More/better examples
+	* Added t/76_magic.t
+
 2008-04-11  0.41 - H.Merijn Brand   <h.m.brand at xs4all.nl>
 
 	* error_diag () subclassable

Modified: branches/upstream/libtext-csv-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libtext-csv-perl/current/MANIFEST?rev=18736&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/MANIFEST (original)
+++ branches/upstream/libtext-csv-perl/current/MANIFEST Thu Apr 17 20:21:09 2008
@@ -23,6 +23,7 @@
 t/65_allow.t		Allow bad formats
 t/70_rt.t		Tests based on RT reports
 t/75_hashref.t		getline_hr related tests
+t/76_magic.t		array_ref from magig
 t/80_diag.t		Error diagnostics
 t/util.pl		Extra test utilities
 examples/csv2xls	Script to onvert CSV files to M$Excel

Modified: branches/upstream/libtext-csv-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libtext-csv-perl/current/META.yml?rev=18736&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/META.yml (original)
+++ branches/upstream/libtext-csv-perl/current/META.yml Thu Apr 17 20:21:09 2008
@@ -1,19 +1,28 @@
 --- #YAML:1.0
-name:                Text-CSV_XS
-version:             0.41
-abstract:            Comma-Separated Values manipulation routines
-license:             perl
+name:              Text-CSV_XS
+version:           0.42
+abstract:          Comma-Separated Values manipulation routines
+license:           perl
 author:              
     - H.Merijn Brand <h.merijn at xs4all.nl>
-generated_by:        ExtUtils::MakeMaker version 6.44
-distribution_type:   module
+generated_by:      Author
+distribution_type: module
+provides:
+    Text::CSV_XS:
+        file:      CSV_XS.pm
+        version:   0.42
 requires:     
-    perl:                      5.005
-    Config:                        0
-    DynaLoader:                    0
-    IO::Handle:                    0
-    Test::Harness:                 0
-    Test::More:                    0
+    perl:          5.005
+    DynaLoader:    0
+    IO::Handle:    0
+build_requires:
+    perl:          5.005
+    Config:        0
+    Test::Harness: 0
+    Test::More:    0
+    Tie::Scalar:   0
+resources:
+    license:       http://dev.perl.org/licenses/
 meta-spec:
-    url:     http://module-build.sourceforge.net/META-spec-v1.3.html
-    version: 1.3
+    url:           http://module-build.sourceforge.net/META-spec-v1.3.html
+    version:       1.3

Modified: branches/upstream/libtext-csv-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libtext-csv-perl/current/Makefile.PL?rev=18736&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/Makefile.PL (original)
+++ branches/upstream/libtext-csv-perl/current/Makefile.PL Thu Apr 17 20:21:09 2008
@@ -60,7 +60,7 @@
 	'	cover',
 	'',
 	'fixmeta:	distmeta',
-	'	$(PERL) -pi -e"/^    Config/ and print qq{    perl:                      5.005\n}" */META.yml',
+	'	perl genMETA.pl',
 	'',
 	'tgzdist:	fixmeta $(DISTVNAME).tar.gz',
 	'	- at mv -f $(DISTVNAME).tar.gz $(DISTVNAME).tgz',

Added: branches/upstream/libtext-csv-perl/current/t/76_magic.t
URL: http://svn.debian.org/wsvn/branches/upstream/libtext-csv-perl/current/t/76_magic.t?rev=18736&op=file
==============================================================================
--- branches/upstream/libtext-csv-perl/current/t/76_magic.t (added)
+++ branches/upstream/libtext-csv-perl/current/t/76_magic.t Thu Apr 17 20:21:09 2008
@@ -1,0 +1,55 @@
+#!/usr/bin/perl
+
+use strict;
+$^W = 1;
+
+#use Test::More "no_plan";
+ use Test::More tests => 5;
+
+BEGIN {
+    use_ok "Text::CSV_XS", ();
+    plan skip_all => "Cannot load Text::CSV_XS" if $@;
+    }
+
+my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\n" });
+
+my $foo;
+my @foo = ("#", 1..3);
+
+tie $foo, "Foo";
+open  FH, ">_test.csv";
+ok ($csv->print (*FH, $foo),		"print with unused magic scalar");
+close FH;
+untie $foo;
+
+open  FH, "<_test.csv";
+is_deeply ($csv->getline (*FH), \@foo,	"Content read-back");
+close FH;
+
+tie $foo, "Foo";
+ok ($csv->column_names ($foo),		"column_names () from magic");
+untie $foo;
+is_deeply ([$csv->column_names], \@foo,	"column_names ()");
+
+unlink "_test.csv";
+
+package Foo;
+
+use strict;
+local $^W = 1;
+
+require Tie::Scalar;
+use vars qw( @ISA );
+ at ISA = qw(Tie::Scalar);
+
+sub FETCH
+{
+    [ "#", 1 .. 3 ];
+    } # FETCH
+
+sub TIESCALAR
+{
+    bless [], "Foo";
+    } # TIESCALAR
+
+1;




More information about the Pkg-perl-cvs-commits mailing list