r33398 - in /branches/upstream/libclass-dbi-asform-perl: ./ current/ current/lib/ current/lib/Class/ current/lib/Class/DBI/ current/t/

ryan52-guest at users.alioth.debian.org ryan52-guest at users.alioth.debian.org
Thu Apr 16 03:31:48 UTC 2009


Author: ryan52-guest
Date: Thu Apr 16 03:31:43 2009
New Revision: 33398

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=33398
Log:
[svn-inject] Installing original source of libclass-dbi-asform-perl

Added:
    branches/upstream/libclass-dbi-asform-perl/
    branches/upstream/libclass-dbi-asform-perl/current/
    branches/upstream/libclass-dbi-asform-perl/current/Changes
    branches/upstream/libclass-dbi-asform-perl/current/MANIFEST
    branches/upstream/libclass-dbi-asform-perl/current/META.yml
    branches/upstream/libclass-dbi-asform-perl/current/Makefile.PL
    branches/upstream/libclass-dbi-asform-perl/current/README
    branches/upstream/libclass-dbi-asform-perl/current/lib/
    branches/upstream/libclass-dbi-asform-perl/current/lib/Class/
    branches/upstream/libclass-dbi-asform-perl/current/lib/Class/DBI/
    branches/upstream/libclass-dbi-asform-perl/current/lib/Class/DBI/AsForm.pm
    branches/upstream/libclass-dbi-asform-perl/current/t/
    branches/upstream/libclass-dbi-asform-perl/current/t/01.t
    branches/upstream/libclass-dbi-asform-perl/current/t/pod-coverage.t
    branches/upstream/libclass-dbi-asform-perl/current/t/pod.t

Added: branches/upstream/libclass-dbi-asform-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-asform-perl/current/Changes?rev=33398&op=file
==============================================================================
--- branches/upstream/libclass-dbi-asform-perl/current/Changes (added)
+++ branches/upstream/libclass-dbi-asform-perl/current/Changes Thu Apr 16 03:31:43 2009
@@ -1,0 +1,35 @@
+Revision history for Perl extension Class::DBI::AsForm.
+
+2.42  Tue Sep  6 22:22:48 UTC 2005
+    - Switch tests to SQLite 
+
+2.41  Dec 27 2004
+    - Add rows & cols to textarea [Marcus Ramberg]
+
+2.4   Dec 27 2004
+    - Tony Bowden now maintainer
+    - switch to DBD::SQLite2 for tests
+
+2.3   Mon Jul 19 12:22:50 BST 2004
+    - Patch from Randall Lucas to fix textarea breakage
+    - The tests work too
+
+2.2   Sat Mar 20 17:36:02 GMT 2004
+    - use the ::Type plugin instead of that mysql ugliness.
+
+2.1   Thu Jan 29 14:51:31 GMT 2004
+    - 2.0 was a rewrite to use HTML::Element
+    - This release fixes cases where value => ""
+    - And makes "selected" work OK
+    - And deals with nulls in has-a relationships, since I managed to
+      forget about that again.
+    - Make the type detection stuff actually work. Hah.
+    - Yes, I know there's something mysql specific in there.
+
+1.1   Sat Jan 24 19:54:25 GMT 2004
+    - Deal with nulls in has-a relationships.
+
+0.01  Sat Sep 20 12:16:00 2003
+	- original version; created by h2xs 1.21 with options
+		-AX -n Class::DBI::AsForm
+

Added: branches/upstream/libclass-dbi-asform-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-asform-perl/current/MANIFEST?rev=33398&op=file
==============================================================================
--- branches/upstream/libclass-dbi-asform-perl/current/MANIFEST (added)
+++ branches/upstream/libclass-dbi-asform-perl/current/MANIFEST Thu Apr 16 03:31:43 2009
@@ -1,0 +1,9 @@
+Changes
+lib/Class/DBI/AsForm.pm
+Makefile.PL
+MANIFEST			This list of files
+META.yml
+README
+t/01.t
+t/pod-coverage.t
+t/pod.t

Added: branches/upstream/libclass-dbi-asform-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-asform-perl/current/META.yml?rev=33398&op=file
==============================================================================
--- branches/upstream/libclass-dbi-asform-perl/current/META.yml (added)
+++ branches/upstream/libclass-dbi-asform-perl/current/META.yml Thu Apr 16 03:31:43 2009
@@ -1,0 +1,14 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         Class-DBI-AsForm
+version:      2.42
+version_from: lib/Class/DBI/AsForm.pm
+installdirs:  site
+requires:
+    Class::DBI:                    0.94
+    Class::DBI::Plugin::Type:      0
+    DBI:                           1.21
+    HTML::Element:                 0
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17

Added: branches/upstream/libclass-dbi-asform-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-asform-perl/current/Makefile.PL?rev=33398&op=file
==============================================================================
--- branches/upstream/libclass-dbi-asform-perl/current/Makefile.PL (added)
+++ branches/upstream/libclass-dbi-asform-perl/current/Makefile.PL Thu Apr 16 03:31:43 2009
@@ -1,0 +1,13 @@
+use ExtUtils::MakeMaker;
+WriteMakefile(
+	NAME         => 'Class::DBI::AsForm',
+	VERSION_FROM => 'lib/Class/DBI/AsForm.pm',
+	ABSTRACT_FROM => 'lib/Class/DBI/AsForm.pm',          
+	PREREQ_PM    => {
+		'Class::DBI'               => 0.94,
+		'DBI'                      => 1.21,
+		'HTML::Element'            => 0,
+		'Class::DBI::Plugin::Type' => 0,
+	},                                      
+	AUTHOR => 'Tony Bowden <TMTM at cpan.org>'
+);

Added: branches/upstream/libclass-dbi-asform-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-asform-perl/current/README?rev=33398&op=file
==============================================================================
--- branches/upstream/libclass-dbi-asform-perl/current/README (added)
+++ branches/upstream/libclass-dbi-asform-perl/current/README Thu Apr 16 03:31:43 2009
@@ -1,0 +1,75 @@
+NAME
+    Class::DBI::AsForm - Produce HTML form elements for database columns
+
+SYNOPSIS
+        package Music::CD;
+        use Class::DBI::AsForm;
+        use base 'Class::DBI';
+        use CGI;
+        ...
+
+        sub create_or_edit {
+            my $class = shift;
+            my %cgi_field = $class->to_cgi;
+            return start_form,
+                   (map { "<b>$_</b>: ". $cgi_field{$_}->as_HTML." <br>" } 
+                        $class->Columns),
+                   end_form;
+        }
+
+        # <form method="post"...>
+        # Title: <input type="text" name="Title" /> <br>
+        # Artist: <select name="Artist"> 
+        #           <option value=1>Grateful Dead</option>
+        #           ...
+        #         </select>
+        # ...
+        # </form>
+
+DESCRIPTION
+    This module helps to generate HTML forms for creating new database rows
+    or editing existing rows. It maps column names in a database table to
+    HTML form elements which fit the schema. Large text fields are turned
+    into textareas, and fields with a has-a relationship to other
+    "Class::DBI" tables are turned into select drop-downs populated with
+    objects from the joined class.
+
+METHODS
+    The module is a mix-in which adds two additional methods to your
+    "Class::DBI"-derived class.
+
+  to_cgi
+    This returns a hash mapping all the column names of the class to
+    HTML::Element objects representing form widgets.
+
+  to_field($field [, $how])
+    This maps an individual column to a form element. The "how" argument can
+    be used to force the field type into one of "textfield", "textarea" or
+    "select"; you can use this is you want to avoid the automatic detection
+    of has-a relationships.
+
+CHANGES
+    Version 1.x of this module returned raw HTML instead of "HTML::Element"
+    objects, which made it harder to manipulate the HTML before sending it
+    out. If you depend on the old behaviour, set
+    $Class::DBI::AsForm::OLD_STYLE to a true value.
+
+MAINTAINER
+    Tony Bowden
+
+ORIGINAL AUTHOR
+    Simon Cozens
+
+BUGS and QUERIES
+    Please direct all correspondence regarding this module to:
+    bug-Class-DBI-AsForm at rt.cpan.org
+
+COPYRIGHT AND LICENSE
+    Copyright 2003-2004 by Simon Cozens / Tony Bowden
+
+    This library is free software; you can redistribute it and/or modify it
+    under the same terms as Perl itself.
+
+SEE ALSO
+    Class::DBI, Class::DBI::FromCGI, HTML::Element.
+

Added: branches/upstream/libclass-dbi-asform-perl/current/lib/Class/DBI/AsForm.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-asform-perl/current/lib/Class/DBI/AsForm.pm?rev=33398&op=file
==============================================================================
--- branches/upstream/libclass-dbi-asform-perl/current/lib/Class/DBI/AsForm.pm (added)
+++ branches/upstream/libclass-dbi-asform-perl/current/lib/Class/DBI/AsForm.pm Thu Apr 16 03:31:43 2009
@@ -1,0 +1,174 @@
+package Class::DBI::AsForm;
+
+use 5.006;
+our $VERSION = '2.42';
+
+use strict;
+use warnings;
+
+use base 'Exporter';
+
+use Class::DBI::Plugin::Type ();
+use HTML::Element;
+
+our $OLD_STYLE = 0;
+our @EXPORT    = qw( to_cgi to_field _to_textarea _to_textfield _to_select
+	type_of );
+
+=head1 NAME
+
+Class::DBI::AsForm - Produce HTML form elements for database columns
+
+=head1 SYNOPSIS
+
+    package Music::CD;
+    use Class::DBI::AsForm;
+    use base 'Class::DBI';
+    use CGI;
+    ...
+
+    sub create_or_edit {
+        my $class = shift;
+        my %cgi_field = $class->to_cgi;
+        return start_form,
+               (map { "<b>$_</b>: ". $cgi_field{$_}->as_HTML." <br>" } 
+                    $class->Columns),
+               end_form;
+    }
+
+    # <form method="post"...>
+    # Title: <input type="text" name="Title" /> <br>
+    # Artist: <select name="Artist"> 
+    #           <option value=1>Grateful Dead</option>
+    #           ...
+    #         </select>
+    # ...
+    # </form>
+
+=head1 DESCRIPTION
+
+This module helps to generate HTML forms for creating new database rows
+or editing existing rows. It maps column names in a database table to
+HTML form elements which fit the schema. Large text fields are turned
+into textareas, and fields with a has-a relationship to other
+C<Class::DBI> tables are turned into select drop-downs populated with
+objects from the joined class.
+
+=head1 METHODS
+
+The module is a mix-in which adds two additional methods to your
+C<Class::DBI>-derived class. 
+
+=head2 to_cgi
+
+This returns a hash mapping all the column names of the class to
+HTML::Element objects representing form widgets.
+
+=cut
+
+sub to_cgi {
+	my $class = shift;
+	map { $_ => $class->to_field($_) } $class->columns;
+}
+
+=head2 to_field($field [, $how])
+
+This maps an individual column to a form element. The C<how> argument
+can be used to force the field type into one of C<textfield>, C<textarea>
+or C<select>; you can use this is you want to avoid the automatic detection
+of has-a relationships.
+
+=cut
+
+sub to_field {
+	my ($self, $field, $how) = @_;
+	my $class = ref $self || $self;
+	if ($how and $how =~ /^(text(area|field)|select)$/) {
+		no strict 'refs';
+		my $meth = "_to_$how";
+		return $class->$meth($field);
+	}
+	my $hasa = $class->__hasa_rels->{$field};
+	return $self->_to_select($field, $hasa->[0])
+		if defined $hasa
+		and $hasa->[0]->isa("Class::DBI");
+
+	# Right, have some of this!
+	eval "package $class; Class::DBI::Plugin::Type->import()";
+	my $type = $class->column_type($field);
+	return $self->_to_textarea($field)
+		if $type
+		and $type =~ /^(TEXT|BLOB)$/i;
+	return $self->_to_textfield($field);
+}
+
+sub _to_textarea {
+	my ($self, $col) = @_;
+	my $a =
+		HTML::Element->new("textarea", name => $col, rows => "3", cols => "22");
+	if (ref $self) { $a->push_content($self->$col) }
+	$OLD_STYLE && return $a->as_HTML;
+	$a;
+}
+
+sub _to_textfield {
+	my ($self, $col) = @_;
+	my $value = ref $self && $self->$col;
+	my $a = HTML::Element->new("input", type => "text", name => $col);
+	$a->attr("value" => $value) if $value;
+	$OLD_STYLE && return $a->as_HTML;
+	$a;
+}
+
+sub _to_select {
+	my ($self, $col, $hint) = @_;
+	my $has_a_class = $hint || $self->__hasa_rels->{$col}->[0];
+	my @objs        = $has_a_class->retrieve_all;
+	my $a           = HTML::Element->new("select", name => $col);
+	for (@objs) {
+		my $sel = HTML::Element->new("option", value => $_->id);
+		$sel->attr("selected" => "selected")
+			if ref $self
+			and eval { $_->id eq $self->$col->id };
+		$sel->push_content($_->stringify_self);
+		$a->push_content($sel);
+	}
+	$OLD_STYLE && return $a->as_HTML;
+	$a;
+}
+
+1;
+
+=head1 CHANGES
+
+Version 1.x of this module returned raw HTML instead of
+C<HTML::Element> objects, which made it harder to manipulate the
+HTML before sending it out. If you depend on the old behaviour, set
+C<$Class::DBI::AsForm::OLD_STYLE> to a true value.
+
+=head1 MAINTAINER 
+
+Tony Bowden
+
+=head1 ORIGINAL AUTHOR
+
+Simon Cozens
+
+=head1 BUGS and QUERIES
+
+Please direct all correspondence regarding this module to:
+  bug-Class-DBI-AsForm at rt.cpan.org
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2003-2004 by Simon Cozens / Tony Bowden
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+L<Class::DBI>, L<Class::DBI::FromCGI>, L<HTML::Element>.
+
+=cut
+

Added: branches/upstream/libclass-dbi-asform-perl/current/t/01.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-asform-perl/current/t/01.t?rev=33398&op=file
==============================================================================
--- branches/upstream/libclass-dbi-asform-perl/current/t/01.t (added)
+++ branches/upstream/libclass-dbi-asform-perl/current/t/01.t Thu Apr 16 03:31:43 2009
@@ -1,0 +1,54 @@
+package Foo;
+use Test::More;
+eval "require DBD::SQLite" or plan skip_all => "Couldn't load DBD::SQLite";
+plan tests => 4;
+
+package DBI::Test;
+use base 'Class::DBI';
+
+BEGIN { unlink 'test.db'; };
+DBI::Test->set_db("Main", "dbi:SQLite:dbname=test.db");
+DBI::Test->db_Main->do("CREATE TABLE foo (
+   id integer not null primary key,
+   bar integer,
+   baz varchar(255)
+);");
+DBI::Test->db_Main->do("CREATE TABLE bar (
+   id integer not null primary key,
+   test varchar(255)
+);");
+DBI::Test->table("test");
+package Bar;
+use base 'DBI::Test';
+Bar->table("bar");
+Bar->columns(All => qw/id test/);
+Bar->columns(Stringify => qw/test/);
+sub retrieve_all {
+    bless { test => "Hi", id => 1}, shift;
+}
+
+package Foo;
+use base 'DBI::Test';
+Foo->table("foo");
+use_ok("Class::DBI::AsForm");
+no warnings 'once';
+$Class::DBI::AsForm::OLD_STYLE=1;
+*type_of = sub { "varchar" };
+
+Foo->columns(All => qw/id bar baz/);
+like(Foo->to_field("baz"), qr/<input .*name="baz"/,
+    "Ordinary text field OK");
+
+Foo->has_a(bar => Bar);
+is(Foo->to_field("bar"), "<select name=\"bar\"><option value=1>Hi</option></select>\n",
+    "Select OK");
+
+my $x = bless({id => 1, bar => Bar->retrieve_all(), baz => "Hello there"}, "Foo");
+my %cgi = ( id => '<input name="id" type="text" value=1>
+',
+    bar => '<select name="bar"><option selected value=1>Hi</option></select>
+',
+            baz => '<input name="baz" type="text" value="Hello there">
+'
+          );
+is_deeply({$x->to_cgi}, \%cgi, "All correct as an object method");

Added: branches/upstream/libclass-dbi-asform-perl/current/t/pod-coverage.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-asform-perl/current/t/pod-coverage.t?rev=33398&op=file
==============================================================================
--- branches/upstream/libclass-dbi-asform-perl/current/t/pod-coverage.t (added)
+++ branches/upstream/libclass-dbi-asform-perl/current/t/pod-coverage.t Thu Apr 16 03:31:43 2009
@@ -1,0 +1,4 @@
+use Test::More;
+eval "use Test::Pod::Coverage 1.00";
+plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@;
+all_pod_coverage_ok();

Added: branches/upstream/libclass-dbi-asform-perl/current/t/pod.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-asform-perl/current/t/pod.t?rev=33398&op=file
==============================================================================
--- branches/upstream/libclass-dbi-asform-perl/current/t/pod.t (added)
+++ branches/upstream/libclass-dbi-asform-perl/current/t/pod.t Thu Apr 16 03:31:43 2009
@@ -1,0 +1,4 @@
+use Test::More;
+eval "use Test::Pod 1.00";
+plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
+all_pod_files_ok();




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