[Bast-commits] r4597 - / DBIx-Class-InflateColumn-Path-Class DBIx-Class-InflateColumn-Path-Class/trunk DBIx-Class-InflateColumn-Path-Class/trunk/lib DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/Class DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/Class/InflateColumn DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/Class/InflateColumn/Path DBIx-Class-InflateColumn-Path-Class/trunk/t DBIx-Class-InflateColumn-Path-Class/trunk/t/lib DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/TestDB

groditi at dev.catalyst.perl.org groditi at dev.catalyst.perl.org
Sat Jul 19 22:38:02 BST 2008


Author: groditi
Date: 2008-07-19 22:38:00 +0100 (Sat, 19 Jul 2008)
New Revision: 4597

Added:
   DBIx-Class-InflateColumn-Path-Class/
   DBIx-Class-InflateColumn-Path-Class/branches/
   DBIx-Class-InflateColumn-Path-Class/tags/
   DBIx-Class-InflateColumn-Path-Class/trunk/
   DBIx-Class-InflateColumn-Path-Class/trunk/Changes
   DBIx-Class-InflateColumn-Path-Class/trunk/MANIFEST
   DBIx-Class-InflateColumn-Path-Class/trunk/Makefile.PL
   DBIx-Class-InflateColumn-Path-Class/trunk/README
   DBIx-Class-InflateColumn-Path-Class/trunk/lib/
   DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/
   DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/Class/
   DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/Class/InflateColumn/
   DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/Class/InflateColumn/Path/
   DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/Class/InflateColumn/Path/Class.pm
   DBIx-Class-InflateColumn-Path-Class/trunk/t/
   DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/
   DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/TestDB.pm
   DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/TestDB/
   DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/TestDB/Foo.pm
   DBIx-Class-InflateColumn-Path-Class/trunk/t/path_class.t
Log:
initial checkin

Added: DBIx-Class-InflateColumn-Path-Class/trunk/Changes
===================================================================
--- DBIx-Class-InflateColumn-Path-Class/trunk/Changes	                        (rev 0)
+++ DBIx-Class-InflateColumn-Path-Class/trunk/Changes	2008-07-19 21:38:00 UTC (rev 4597)
@@ -0,0 +1,2 @@
+0.001000 July 19, 2008
+    - Initial Release
\ No newline at end of file

Added: DBIx-Class-InflateColumn-Path-Class/trunk/MANIFEST
===================================================================
--- DBIx-Class-InflateColumn-Path-Class/trunk/MANIFEST	                        (rev 0)
+++ DBIx-Class-InflateColumn-Path-Class/trunk/MANIFEST	2008-07-19 21:38:00 UTC (rev 4597)
@@ -0,0 +1,17 @@
+Changes
+inc/Module/Install.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+lib/DBIx/Class/InflateColumn/Path/Class.pm
+Makefile.PL
+MANIFEST			This list of files
+META.yml
+README
+t/lib/TestDB.pm
+t/lib/TestDB/Foo.pm
+t/path_class.t

Added: DBIx-Class-InflateColumn-Path-Class/trunk/Makefile.PL
===================================================================
--- DBIx-Class-InflateColumn-Path-Class/trunk/Makefile.PL	                        (rev 0)
+++ DBIx-Class-InflateColumn-Path-Class/trunk/Makefile.PL	2008-07-19 21:38:00 UTC (rev 4597)
@@ -0,0 +1,16 @@
+#! /usr/bin/perl -w
+
+# Load the Module::Install bundled in ./inc/
+use inc::Module::Install;
+
+# Define metadata
+name 'DBIx-Class-InflateColumn-Path-Class';
+abstract "INflate columns into Path::Class objects";
+all_from 'lib/DBIx/Class/InflateColumn/Path/Class.pm';
+
+# Specific dependencies
+requires 'DBIx::Class';
+requires 'Path::Class';
+build_requires 'Test::More';
+
+WriteAll;

Added: DBIx-Class-InflateColumn-Path-Class/trunk/README
===================================================================
--- DBIx-Class-InflateColumn-Path-Class/trunk/README	                        (rev 0)
+++ DBIx-Class-InflateColumn-Path-Class/trunk/README	2008-07-19 21:38:00 UTC (rev 4597)
@@ -0,0 +1,4 @@
+perl Makefile.PL
+make test
+sudo make install
+make clean
\ No newline at end of file

Added: DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/Class/InflateColumn/Path/Class.pm
===================================================================
--- DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/Class/InflateColumn/Path/Class.pm	                        (rev 0)
+++ DBIx-Class-InflateColumn-Path-Class/trunk/lib/DBIx/Class/InflateColumn/Path/Class.pm	2008-07-19 21:38:00 UTC (rev 4597)
@@ -0,0 +1,84 @@
+package DBIx::Class::InflateColumn::Path::Class;
+
+use strict;
+use warnings;
+use Path::Class;
+
+our $VERSION = '0.001000';
+
+sub register_column {
+  my ($self, $column, $info, @rest) = @_;
+  $self->next::method($column, $info, @rest);
+
+  my $inflate;
+  if( exists $info->{'is_file'} || $info->{'is_file'} ){
+    $inflate = sub { return Path::Class::file(shift) };
+  } elsif( exists $info->{'is_dir'} || $info->{'is_dir'} ){
+    $inflate = sub { return Path::Class::dir(shift) };
+  } else {
+    return;
+  }
+
+  $self->inflate_column
+    (
+     $column => {
+                 inflate => $inflate,
+                 deflate => sub { return shift->stringify },
+                }
+    );
+}
+
+1;
+
+__END__;
+
+=head1 NAME
+
+DBIx::Class::InflateColumn::Path::Class
+
+=head1 SYNOPSIS
+
+  __PACKAGE__->load_components(qw/InflateColumn::Path::Class Core/);
+  __PACKAGE__->add_columns(
+      file_path => {
+          datatype => 'TEXT',
+          size     => 65535,
+          is_nullable => 1,
+          is_file => 1, #or is_dir => 1
+      },
+  )
+   
+  #...
+   
+   $obj->file_path->basename;
+
+=head1 DESCRIPTION
+
+This module inflates/deflates designated columns into L<Path::Class::File> or
+L<Path::Class::Dir> objects.
+
+=head1 METHODS
+
+=head2 register_column
+
+Extends the original method to setup inflators and deflators for the column.
+This is an internal method and you should never really have to use it.
+
+=head1 SEE ALSO
+
+L<Path::Class>
+L<DBIx::Class>
+L<DBIx::Class::InflateColumn>
+
+=head1 AUTHOR
+
+Guillermo Roditi (groditi) E<lt>groditi at cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2008 by Guillermo Roditi
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut

Added: DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/TestDB/Foo.pm
===================================================================
--- DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/TestDB/Foo.pm	                        (rev 0)
+++ DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/TestDB/Foo.pm	2008-07-19 21:38:00 UTC (rev 4597)
@@ -0,0 +1,35 @@
+package TestDB::Foo;
+
+use strict;
+use warnings;
+use base 'DBIx::Class';
+
+__PACKAGE__->load_components(qw/InflateColumn::Path::Class Core/);
+__PACKAGE__->table('foo');
+__PACKAGE__->add_columns
+  (
+   id => {
+          data_type => 'INT',
+          is_nullable => 0,
+          extras => {unsigned => 1 },
+          is_auto_increment => 1,
+    },
+   file_path => {
+                 data_type => 'VARCHAR',
+                 size => 255,
+                 is_nullable => 0,
+                 is_file => 1,
+    },
+   dir_path => {
+                data_type => 'VARCHAR',
+                size => 255,
+                is_nullable => 0,
+                is_dir => 1,
+               },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;
+
+__END__;

Added: DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/TestDB.pm
===================================================================
--- DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/TestDB.pm	                        (rev 0)
+++ DBIx-Class-InflateColumn-Path-Class/trunk/t/lib/TestDB.pm	2008-07-19 21:38:00 UTC (rev 4597)
@@ -0,0 +1,35 @@
+package TestDB;
+
+use strict;
+use warnings;
+use Path::Class ();
+use base 'DBIx::Class::Schema';
+
+my $db = Path::Class::file(qw/t var test.db/);
+
+sub init_schema {
+  my $self = shift;
+  $db->dir->rmtree if -e $db->dir;
+
+  $db->dir->mkpath;
+
+  my $dsn = 'dbi:SQLite:' . $db;
+  my $schema = $self->connect($dsn);
+    $schema->storage->on_connect_do([
+        'PRAGMA synchronous = OFF',
+        'PRAGMA temp_store = MEMORY'
+    ]);
+
+  $schema->deploy;
+
+  return $schema;
+
+}
+
+sub DESTROY {
+  $db->dir->rmtree if -e $db->dir;
+}
+
+__PACKAGE__->load_classes;
+
+1;

Added: DBIx-Class-InflateColumn-Path-Class/trunk/t/path_class.t
===================================================================
--- DBIx-Class-InflateColumn-Path-Class/trunk/t/path_class.t	                        (rev 0)
+++ DBIx-Class-InflateColumn-Path-Class/trunk/t/path_class.t	2008-07-19 21:38:00 UTC (rev 4597)
@@ -0,0 +1,54 @@
+#!perl -wT
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+    use lib 't/lib';
+    use TestDB;
+
+    eval 'require DBD::SQLite';
+    if($@) {
+        plan skip_all => 'DBD::SQLite not installed';
+      } else {
+        plan tests => 15;
+      };
+
+    use_ok('Path::Class');
+  };
+
+my $schema = TestDB->init_schema;
+
+my $rel_file = Path::Class::file('rel','file.txt');
+my $abs_file = Path::Class::file('/','abs','file.txt');
+ok(  $abs_file->is_absolute );
+ok( !$rel_file->is_absolute );
+
+my $rs = $schema->resultset('Foo');
+
+my $row = $rs->create({
+             id => 1,
+             file_path => $rel_file,
+             dir_path => $rel_file->dir,
+            });
+
+$rs->create({
+             id => 2,
+             file_path => $abs_file,
+             dir_path => $abs_file->dir,
+            });
+
+isa_ok($row->dir_path, 'Path::Class::Dir');
+isa_ok($row->file_path, 'Path::Class::File');
+is($row->dir_path->stringify, 'rel', 'relative dir' );
+is($row->file_path->stringify, 'rel/file.txt', 'relative file' );
+ok( !$row->file_path->dir->is_absolute );
+ok( !$row->file_path->is_absolute );
+
+my $row2 = $rs->find({id => 2});
+isa_ok($row2->dir_path, 'Path::Class::Dir');
+isa_ok($row2->file_path, 'Path::Class::File');
+is($row2->dir_path->stringify, '/abs', 'relative dir' );
+is($row2->file_path->stringify, '/abs/file.txt', 'relative file' );
+ok( $row2->file_path->dir->is_absolute );
+ok( $row2->file_path->is_absolute );




More information about the Bast-commits mailing list