HTML-FormFu-Model-DBIC-1.00 000755 000764 000764 0 12253556454 15715 5 ustar 00cafranks cafranks 000000 000000 README 100644 000764 000764 471 12253556454 16640 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00
This archive contains the distribution HTML-FormFu-Model-DBIC,
version 1.00:
Integrate HTML::FormFu with DBIx::Class
This software is copyright (c) 2013 by Carl Franks.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Changes 100644 000764 000764 10515 12253556454 17313 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00 1.00 2013-12-16
- tests updated for HTML-FormFu v1.00 changes
0.09010 2012-10-05
- Support belongs_to rel with a ComboBox element.
- localize_label works with non-column label accessors.
- Add support to create required belongs_to rels (pshangov).
- options_from_model() can populate from DBIx::Class ENUM values.
- Constraint::DBIC::Unique - new id_field() and method_name() methods.
- Constraint::DBIC::Unique - others() now supports nested_names values.
- Require HTML-FormFu v0.09010 due to internals used by
Constraint::DBIC::Unique
0.09000 2011-03-29
- Updated to work with HTML-FormFu 0.09000
- condition_from_stash now accepts hash from stash, but not from config.
0.08002 2010-09-22
- Incompatible Change: removed all previously deprecated methods.
- Fix: Was trying to pass undef to NOT NULL columns - changed check from
( $is_nullable || ... ) to ( $is_nullable && ... )
appears to have been unintentionally changed in svn r93 when the code
was a part of DBIx::Class::HTML::FormFu.
- many-to-many handling with restricting condition tests and code
to prevent deleting outside of restriction in update code.
- New 'others' option for Constraint::DBIC::Unique.
- Constraint::DBIC::Unique tests added.
0.06000 2009-12-10
- Test suite now uses in-memory SQLite database, so tests can be run in
parallel.
- many-to-many Checkboxgroup tests.
0.05003 2009-11-25
- New 'link_values' and 'additive' options for multi-value fields for
many-to-many relationships.
- Doc updates.
0.05002 2009-07-06
- Remove prerequisite Test::MockObject - it uses UNIVERSAL::isa which
was causing test failures.
0.05001 2009-07-03
- Fix delete_if_true to work inside a surrounding block.
- Made DBIC deletes conditional on row being in_storage.
- Bump DBIx::Class prerequisite to 0.08106, when it switched from using
DateTime::Format::MySQL to DateTime::Format::SQLite.
0.05000 2009-05-26
- Fix update() "primary key and the foreign key may not be the same column"
errors.
- options_from_model() 'label_col' works again with non-column accessors.
0.04003 2009-05-10
- Bumped prerequisite HTML-FormFu to 0.04002
0.04002 2009-05-08
- New "empty_rows" setting - replaces now deprecated "new_empty_row".
- New "new_rows_max" setting - replaces now deprecated "new_empty_row_multi".
- Previously, the field named in "new_empty_row" was used to determine
whether to insert a new row. - Now we simply insert a new row if any
field within the Repeatable block has a submitted value.
- New 'read_only' model_config option.
- New 'ignore_if_empty' model_config option.
- Support nested Repeatable elements.
0.04000 2009-04-22
- New "empty_rows" setting - replaces now deprecated "new_empty_row".
- New "new_rows_max" setting - replaces now deprecated "new_empty_row_multi".
- Previously, the field named in "new_empty_row" was used to determine
whether to insert a new row. - Now we simply insert a new row if any
field within the Repeatable block has a submitted value.
0.03007 2008-12-08
- Bump required version no. of HTML-FormFu to 0.03007
0.03006 2008-12-03
- options_from_model() - If we've a Catalyst context but no schema on
the form stash, use config values for 'model' and 'resultset'
- update() - if a checkbox/radio value isn't submitted, and the column
is NOT NULL, set it to 0 (zero), not DEFAULT VALUE.
- Tests for new ComboBox element.
- Modified delete_if_true example to no longer use "delete" as a
form item name - this is bad!
0.03003 2008-08-21
- Updated to work with is_field/is_block changes in HTML-FormFu
0.03002 2008-08-11
- New {label} setting.
- New {new_empty_row_multi} setting.
- Allow {nested_base} on non-column, non-rel methods.
- Bugfix: RT#35861 - not all non-field elements have a nested_name() method.
- Bugfix: use new_related() instead of create_related() before setting
column values, to ensure we don't die on NOT NULL columns.
0.03000 2008-06-19
- First CPAN release
- HTML::FormFu::Model::DBIC moved out of HTML::FormFu distribution
LICENSE 100644 000764 000764 43650 12253556454 17033 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00 This software is copyright (c) 2013 by Carl Franks.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Terms of the Perl programming language system itself
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
This software is Copyright (c) 2013 by Carl Franks.
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
51 Franklin St, Suite 500, Boston, MA 02110-1335 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you".
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:
a) cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
--- The Artistic License 1.0 ---
This software is Copyright (c) 2013 by Carl Franks.
This is free software, licensed under:
The Artistic License 1.0
The Artistic License
Preamble
The intent of this document is to state the conditions under which a Package
may be copied, such that the Copyright Holder maintains some semblance of
artistic control over the development of the package, while giving the users of
the package the right to use and distribute the Package in a more-or-less
customary fashion, plus the right to make reasonable modifications.
Definitions:
- "Package" refers to the collection of files distributed by the Copyright
Holder, and derivatives of that collection of files created through
textual modification.
- "Standard Version" refers to such a Package if it has not been modified,
or has been modified in accordance with the wishes of the Copyright
Holder.
- "Copyright Holder" is whoever is named in the copyright or copyrights for
the package.
- "You" is you, if you're thinking about copying or distributing this Package.
- "Reasonable copying fee" is whatever you can justify on the basis of media
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or an
equivalent medium, or placing the modifications on a major archive site
such as ftp.uu.net, or by allowing the Copyright Holder to include your
modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict with
standard executables, which must also be provided, and provide a separate
manual page for each non-standard executable that clearly documents how it
differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where to
get the Standard Version.
b) accompany the distribution with the machine-readable source of the Package
with your modifications.
c) accompany any non-standard executables with their corresponding Standard
Version executables, giving the non-standard executables non-standard
names, and clearly documenting the differences in manual pages (or
equivalent), together with instructions on where to get the Standard
Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this Package. You
may not charge a fee for this Package itself. However, you may distribute this
Package in aggregate with other (possibly commercial) programs as part of a
larger (possibly commercial) software distribution provided that you do not
advertise this Package as a product of your own.
6. The scripts and library files supplied as input to or produced as output
from the programs of this Package do not automatically fall under the copyright
of this Package, but belong to whomever generated them, and may be sold
commercially, and may be aggregated with this Package.
7. C or perl subroutines supplied by you and linked into this Package shall not
be considered part of this Package.
8. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.
9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
dist.ini 100644 000764 000764 1234 12253556454 17442 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00 name = HTML-FormFu-Model-DBIC
author = Carl Franks
license = Perl_5
copyright_holder = Carl Franks
copyright_year = 2013
version = 1.00
[Prereqs]
perl = 5.008001
DBD::SQLite = 0
DBIx::Class = 0.08108
HTML::FormFu = 1.00
List::MoreUtils = 0
Storable = 0
Task::Weaken = 0 ; make sure Scalar::Util has weaken()
[Prereqs / TestRequires]
DateTime::Format::SQLite = 0
Locale::Maketext = 0
SQL::Translator = 0 ; for $schema->deploy()
Test::Aggregate::Nested = 0.371
Test::More = 0.99
[Prereqs / DevelopRequires]
Test::Pod = 0
[PodCoverageTests]
[PodSyntaxTests]
[PkgVersion]
[NextRelease]
format = %v %{yyyy-MM-dd}d
[Repository]
[@Basic]
META.yml 100644 000764 000764 1370 12253556454 17250 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00 ---
abstract: 'Integrate HTML::FormFu with DBIx::Class'
author:
- 'Carl Franks '
build_requires:
DateTime::Format::SQLite: 0
Locale::Maketext: 0
SQL::Translator: 0
Test::Aggregate::Nested: 0.371
Test::More: 0.99
configure_requires:
ExtUtils::MakeMaker: 6.30
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.006, CPAN::Meta::Converter version 2.133380'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: HTML-FormFu-Model-DBIC
requires:
DBD::SQLite: 0
DBIx::Class: 0.08108
HTML::FormFu: 1.00
List::MoreUtils: 0
Storable: 0
Task::Weaken: 0
perl: 5.008001
resources:
repository: git://github.com/fireartist/HTML-FormFu-Model-DBIC.git
version: 1.00
MANIFEST 100644 000764 000764 21757 12253556454 17163 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00 Changes
LICENSE
MANIFEST
META.yml
Makefile.PL
README
dist.ini
lib/HTML/FormFu/Constraint/DBIC/Unique.pm
lib/HTML/FormFu/Model/DBIC.pm
t-aggregate/constraints/dbic_unique.t
t-aggregate/constraints/dbic_unique.yml
t-aggregate/constraints/dbic_unique_column.yml
t-aggregate/constraints/dbic_unique_id_field.yml
t-aggregate/constraints/dbic_unique_method.yml
t-aggregate/constraints/dbic_unique_others.yml
t-aggregate/constraints/dbic_unique_repeatable_id_field.t
t-aggregate/constraints/dbic_unique_repeatable_id_field.yml
t-aggregate/create/basic.t
t-aggregate/create/basic.yml
t-aggregate/default_values/basic.t
t-aggregate/default_values/basic.yml
t-aggregate/default_values/basic_nested.t
t-aggregate/default_values/basic_nested.yml
t-aggregate/default_values/belongs_to_lookup_table.t
t-aggregate/default_values/belongs_to_lookup_table.yml
t-aggregate/default_values/belongs_to_lookup_table_combobox.t
t-aggregate/default_values/belongs_to_lookup_table_combobox.yml
t-aggregate/default_values/empty_rows_zero.t
t-aggregate/default_values/empty_rows_zero.yml
t-aggregate/default_values/has_many_combobox.t
t-aggregate/default_values/has_many_combobox.yml
t-aggregate/default_values/has_many_repeatable.t
t-aggregate/default_values/has_many_repeatable.yml
t-aggregate/default_values/has_many_repeatable_delete_true.t
t-aggregate/default_values/has_many_repeatable_delete_true.yml
t-aggregate/default_values/has_many_repeatable_label.t
t-aggregate/default_values/has_many_repeatable_label.yml
t-aggregate/default_values/has_many_repeatable_nested.t
t-aggregate/default_values/has_many_repeatable_nested.yml
t-aggregate/default_values/has_many_repeatable_new.t
t-aggregate/default_values/has_many_repeatable_new.yml
t-aggregate/default_values/has_many_select.t
t-aggregate/default_values/has_many_select.yml
t-aggregate/default_values/has_one.t
t-aggregate/default_values/has_one.yml
t-aggregate/default_values/has_one_nested.t
t-aggregate/default_values/has_one_nested.yml
t-aggregate/default_values/label.t
t-aggregate/default_values/label.yml
t-aggregate/default_values/many_to_many-has_many.t
t-aggregate/default_values/many_to_many-has_many.yml
t-aggregate/default_values/many_to_many_checkboxgroup.t
t-aggregate/default_values/many_to_many_checkboxgroup.yml
t-aggregate/default_values/many_to_many_repeatable.t
t-aggregate/default_values/many_to_many_repeatable.yml
t-aggregate/default_values/many_to_many_repeatable_nested.t
t-aggregate/default_values/many_to_many_repeatable_nested.yml
t-aggregate/default_values/many_to_many_repeatable_new.t
t-aggregate/default_values/many_to_many_repeatable_new.yml
t-aggregate/default_values/many_to_many_select.t
t-aggregate/default_values/many_to_many_select.yml
t-aggregate/default_values/many_to_many_select_nested.t
t-aggregate/default_values/many_to_many_select_nested.yml
t-aggregate/default_values/methods.t
t-aggregate/default_values/methods.yml
t-aggregate/default_values/might_have.t
t-aggregate/default_values/might_have.yml
t-aggregate/default_values/might_have_missing.t
t-aggregate/default_values/multi_label.t
t-aggregate/default_values/multi_label.yml
t-aggregate/default_values/nested_name_accessor.t
t-aggregate/default_values/nested_name_accessor.yml
t-aggregate/default_values/opt_accessor.t
t-aggregate/default_values/opt_accessor.yml
t-aggregate/default_values/opt_accessor_nested.t
t-aggregate/default_values/opt_accessor_nested.yml
t-aggregate/multiform/0_render_page_1.t
t-aggregate/multiform/1_submit_page_1.t
t-aggregate/multiform/2_render_page_2.t
t-aggregate/multiform/3_submit_page_2.t
t-aggregate/multiform/multiform.yml
t-aggregate/options_from_model/belongs_to.t
t-aggregate/options_from_model/belongs_to.yml
t-aggregate/options_from_model/belongs_to_combobox.t
t-aggregate/options_from_model/belongs_to_combobox.yml
t-aggregate/options_from_model/belongs_to_config_zero.t
t-aggregate/options_from_model/belongs_to_config_zero.yml
t-aggregate/options_from_model/belongs_to_config_zero_combobox.t
t-aggregate/options_from_model/belongs_to_config_zero_combobox.yml
t-aggregate/options_from_model/belongs_to_localize_label.t
t-aggregate/options_from_model/belongs_to_localize_label.yml
t-aggregate/options_from_model/condition_from_stash.t
t-aggregate/options_from_model/condition_from_stash.yml
t-aggregate/options_from_model/condition_from_stash_combobox.t
t-aggregate/options_from_model/condition_from_stash_combobox.yml
t-aggregate/options_from_model/condition_from_stash_combobox_complex.t
t-aggregate/options_from_model/condition_from_stash_complex.t
t-aggregate/options_from_model/constraint_autoset.t
t-aggregate/options_from_model/constraint_autoset.yml
t-aggregate/options_from_model/enum_select.t
t-aggregate/options_from_model/enum_select.yml
t-aggregate/options_from_model/has_many_repeatable_select.t
t-aggregate/options_from_model/has_many_repeatable_select.yml
t-aggregate/options_from_model/many_to_many_select.t
t-aggregate/options_from_model/many_to_many_select.yml
t-aggregate/options_from_model/many_to_many_select_restricted.t
t-aggregate/options_from_model/many_to_many_select_restricted.yml
t-aggregate/update/add_valid.t
t-aggregate/update/basic.yml
t-aggregate/update/basic_create.t
t-aggregate/update/basic_update.t
t-aggregate/update/belongs_to.t
t-aggregate/update/belongs_to_combobox.t
t-aggregate/update/belongs_to_create.t
t-aggregate/update/belongs_to_create_required.t
t-aggregate/update/belongs_to_lookup_table_combobox.t
t-aggregate/update/belongs_to_lookup_table_combobox.yml
t-aggregate/update/belongs_to_select.t
t-aggregate/update/belongs_to_select.yml
t-aggregate/update/belongs_to_select_two.yml
t-aggregate/update/column_without_field.t
t-aggregate/update/column_without_field.yml
t-aggregate/update/has_many_repeatable.t
t-aggregate/update/has_many_repeatable.yml
t-aggregate/update/has_many_repeatable_delete_true.t
t-aggregate/update/has_many_repeatable_delete_true.yml
t-aggregate/update/has_many_repeatable_many_new.t
t-aggregate/update/has_many_repeatable_many_new.yml
t-aggregate/update/has_many_repeatable_many_new_exceed_max.t
t-aggregate/update/has_many_repeatable_new.t
t-aggregate/update/has_many_repeatable_new.yml
t-aggregate/update/has_many_repeatable_new_date.t
t-aggregate/update/has_many_repeatable_new_date.yml
t-aggregate/update/has_many_repeatable_new_dependon.t
t-aggregate/update/has_many_repeatable_new_dependon.yml
t-aggregate/update/has_many_repeatable_new_empty.t
t-aggregate/update/has_many_repeatable_new_implicit.t
t-aggregate/update/has_many_repeatable_new_implicit.yml
t-aggregate/update/has_many_repeatable_new_required_when.t
t-aggregate/update/has_many_repeatable_new_required_when.yml
t-aggregate/update/has_one.t
t-aggregate/update/has_one.yml
t-aggregate/update/has_one_create.t
t-aggregate/update/has_one_no_id.t
t-aggregate/update/has_one_no_id.yml
t-aggregate/update/has_one_select.t
t-aggregate/update/has_one_select.yml
t-aggregate/update/ignore_if_empty.t
t-aggregate/update/ignore_if_empty.yml
t-aggregate/update/many_to_many-has_many.t
t-aggregate/update/many_to_many_checkboxgroup.t
t-aggregate/update/many_to_many_checkboxgroup.yml
t-aggregate/update/many_to_many_checkboxgroup_read_only.t
t-aggregate/update/many_to_many_checkboxgroup_read_only.yml
t-aggregate/update/many_to_many_checkboxgroup_restricted.t
t-aggregate/update/many_to_many_checkboxgroup_restricted.yml
t-aggregate/update/many_to_many_checkboxgroup_unselected.t
t-aggregate/update/many_to_many_repeatable.t
t-aggregate/update/many_to_many_repeatable.yml
t-aggregate/update/many_to_many_repeatable_new.t
t-aggregate/update/many_to_many_repeatable_new.yml
t-aggregate/update/many_to_many_select.t
t-aggregate/update/many_to_many_select.yml
t-aggregate/update/many_to_many_select_additive.yml
t-aggregate/update/many_to_many_select_unselected.t
t-aggregate/update/methods.t
t-aggregate/update/methods.yml
t-aggregate/update/might_have.t
t-aggregate/update/might_have.yml
t-aggregate/update/might_have_create.t
t-aggregate/update/might_have_delete_if_empty.t
t-aggregate/update/might_have_delete_if_empty.yml
t-aggregate/update/nested.yml
t-aggregate/update/nested_create.t
t-aggregate/update/nested_create_checkbox.t
t-aggregate/update/nested_name_accessor.t
t-aggregate/update/nested_repeatable_write.t
t-aggregate/update/nested_repeatable_write.yml
t-aggregate/update/null_if_empty.t
t-aggregate/update/null_if_empty.yml
t-aggregate/update/opt_accessor.t
t-aggregate/update/opt_accessor.yml
t-aggregate/update/opt_accessor_nested.t
t-aggregate/update/opt_accessor_nested.yml
t-aggregate/update/unchecked_not_null_checkbox.t
t-aggregate/x_roundtrip/checkbox.yml
t-aggregate/x_roundtrip/checkbox_false2true.t
t-aggregate/x_roundtrip/checkbox_true2false.t
t/aggregate.t
t/lib/DBICTestLib.pm
t/lib/HTMLFormFu/I18N.pm
t/lib/HTMLFormFu/I18N/en.pm
t/lib/HTMLFormFu/MockContext.pm
t/lib/MySchema.pm
t/lib/MySchema/Address.pm
t/lib/MySchema/Band.pm
t/lib/MySchema/HasMany.pm
t/lib/MySchema/ManagedBand.pm
t/lib/MySchema/Manager.pm
t/lib/MySchema/Master.pm
t/lib/MySchema/Note.pm
t/lib/MySchema/Schedule.pm
t/lib/MySchema/Task.pm
t/lib/MySchema/TwoNote.pm
t/lib/MySchema/Type.pm
t/lib/MySchema/Type2.pm
t/lib/MySchema/User.pm
t/lib/MySchema/UserBand.pm
t/lib/MySchemaRS/User.pm
Makefile.PL 100644 000764 000764 3020 12253556454 17743 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00
use strict;
use warnings;
use 5.008001;
use ExtUtils::MakeMaker 6.30;
my %WriteMakefileArgs = (
"ABSTRACT" => "Integrate HTML::FormFu with DBIx::Class",
"AUTHOR" => "Carl Franks ",
"BUILD_REQUIRES" => {},
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => "6.30"
},
"DISTNAME" => "HTML-FormFu-Model-DBIC",
"EXE_FILES" => [],
"LICENSE" => "perl",
"NAME" => "HTML::FormFu::Model::DBIC",
"PREREQ_PM" => {
"DBD::SQLite" => 0,
"DBIx::Class" => "0.08108",
"HTML::FormFu" => "1.00",
"List::MoreUtils" => 0,
"Storable" => 0,
"Task::Weaken" => 0
},
"TEST_REQUIRES" => {
"DateTime::Format::SQLite" => 0,
"Locale::Maketext" => 0,
"SQL::Translator" => 0,
"Test::Aggregate::Nested" => "0.371",
"Test::More" => "0.99"
},
"VERSION" => "1.00",
"test" => {
"TESTS" => "t/*.t"
}
);
my %FallbackPrereqs = (
"DBD::SQLite" => 0,
"DBIx::Class" => "0.08108",
"DateTime::Format::SQLite" => 0,
"HTML::FormFu" => "1.00",
"List::MoreUtils" => 0,
"Locale::Maketext" => 0,
"SQL::Translator" => 0,
"Storable" => 0,
"Task::Weaken" => 0,
"Test::Aggregate::Nested" => "0.371",
"Test::More" => "0.99"
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
delete $WriteMakefileArgs{TEST_REQUIRES};
delete $WriteMakefileArgs{BUILD_REQUIRES};
$WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs;
}
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
WriteMakefile(%WriteMakefileArgs);
t 000755 000764 000764 0 12253556454 16101 5 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00 aggregate.t 100644 000764 000764 256 12253556454 20337 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t use strict;
use warnings;
use Test::More;
use Test::Aggregate::Nested;
Test::Aggregate::Nested->new( {
dirs => 't-aggregate',
# verbose => 1,
} )->run;
lib 000755 000764 000764 0 12253556454 16647 5 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t MySchema.pm 100644 000764 000764 156 12253556454 21035 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib package MySchema;
use strict;
use warnings;
use base 'DBIx::Class::Schema';
__PACKAGE__->load_classes;
1;
DBICTestLib.pm 100644 000764 000764 1034 12253556454 21333 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib package DBICTestLib;
use strict;
use warnings;
use DBI;
use base 'Exporter';
our @EXPORT_OK = qw/ new_schema /;
sub new_schema {
my $schema = MySchema->connect('dbi:SQLite:dbname=:memory:');
$schema->deploy;
$schema->resultset('Type')->create({ id => 1, type => 'foo' });
$schema->resultset('Type')->create({ id => 2, type => 'bar' });
$schema->resultset('Type2')->create({ id => 1, type => 'foo' });
$schema->resultset('Type2')->create({ id => 2, type => 'bar' });
return $schema;
}
1;
MySchema 000755 000764 000764 0 12253556454 20355 5 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib Band.pm 100644 000764 000764 1116 12253556454 21716 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::Band;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("band");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
manager => { data_type => "INTEGER", is_nullable => 1 },
band => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( manager => 'MySchema::Manager' );
__PACKAGE__->has_many( user_bands => 'MySchema::UserBand', 'band' );
__PACKAGE__->many_to_many( users => 'user_bands', 'user' );
1;
Note.pm 100644 000764 000764 706 12253556454 21743 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::Note;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("note");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
master => { data_type => "INTEGER", is_nullable => 0 },
note => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( master => 'MySchema::Master' );
1;
Task.pm 100644 000764 000764 1017 12253556454 21754 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::Task;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("task");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
schedule => { data_type => "INTEGER", is_nullable => 0 },
deadline => { data_type => "DATETIME", is_nullable => 1 },
detail => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( schedule => 'MySchema::Schedule' );
1;
Type.pm 100644 000764 000764 514 12253556454 21754 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::Type;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("type");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
type => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
1;
User.pm 100644 000764 000764 3025 12253556454 21771 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::User;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("user");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
master => { data_type => "INTEGER", is_nullable => 1 },
name => { data_type => "TEXT", is_nullable => 0 },
title => { data_type => "TEXT", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( master => 'MySchema::Master', 'id' );
__PACKAGE__->has_many( addresses => 'MySchema::Address', 'user' );
__PACKAGE__->has_many( user_bands => 'MySchema::UserBand', 'user' );
__PACKAGE__->has_many( hasmanys => 'MySchema::HasMany', 'user' );
__PACKAGE__->many_to_many( bands => 'user_bands', 'band' );
__PACKAGE__->resultset_class('MySchemaRS::User');
sub fullname {
my $self = shift;
if (@_) {
my $fullname = shift;
my $match = qr/
(?: ( \w+ ) \s+ )?
( .* )
/x;
my ($title, $name) = $fullname =~ $match;
$self->set_column( 'title', $title );
$self->set_column( 'name', $name );
return $fullname;
}
my $title = $self->get_column('title');
my $name = $self->get_column('name');
return join ' ', grep {defined} $title, $name;
}
sub foo {
my ($self) = @_;
my $row = $self->find_or_new_related( 'hasmanys', { key => 'foo' } );
if ( @_ > 1 ) {
$row->update(@_);
}
return $row;
}
1;
Type2.pm 100644 000764 000764 516 12253556454 22040 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::Type2;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("type2");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
type => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
1;
HTMLFormFu 000755 000764 000764 0 12253556454 20532 5 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib I18N.pm 100644 000764 000764 267 12253556454 21674 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/HTMLFormFu package HTMLFormFu::I18N;
use strict;
use warnings;
use base 'Locale::Maketext';
*loc = \&localize;
sub localize {
my $self = shift;
return $self->maketext(@_);
}
1;
Master.pm 100644 000764 000764 4555 12253556454 22317 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::Master;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/
InflateColumn::DateTime Core
/);
__PACKAGE__->table("master");
__PACKAGE__->add_columns(
id => {
data_type => "INTEGER",
is_nullable => 0,
},
text_col => { data_type => "TEXT", is_nullable => 1 },
password_col => { data_type => "TEXT", is_nullable => 1 },
checkbox_col => {
data_type => "BOOLEAN",
default_value => 1,
is_nullable => 0,
},
select_col => { data_type => "TEXT", is_nullable => 1 },
combobox_col => { data_type => "TEXT", is_nullable => 1 },
radio_col => { data_type => "TEXT", is_nullable => 1 },
radiogroup_col => { data_type => "TEXT", is_nullable => 1 },
array_col => { data_type => "TEXT", is_nullable => 1, is_array => 1 },
date_col => { data_type => "DATETIME", is_nullable => 1 },
type_id => { data_type => "INTEGER", is_nullable => 1 },
type2_id => { data_type => "INTEGER", is_nullable => 1 },
enum_col => { data_type => "ENUM", is_nullable => 1, extra => { list => [qw( a b c )] } },
not_in_form => { data_type => "TEXT", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->might_have( note => 'MySchema::Note', 'master' );
__PACKAGE__->has_one( user => 'MySchema::User', 'master' );
__PACKAGE__->has_many( schedules => 'MySchema::Schedule', 'master' );
__PACKAGE__->belongs_to(
type => 'MySchema::Type',
{ 'foreign.id' => 'self.type_id' } );
__PACKAGE__->belongs_to(
type2 => 'MySchema::Type2',
{ 'foreign.id' => 'self.type2_id' } );
__PACKAGE__->inflate_column('array_col', { # {key=>val}
inflate => __PACKAGE__->inflate_column_list_comma,
deflate => __PACKAGE__->deflate_column_list_comma,
});
sub method_test {
my $self = shift;
if (@_) {
$self->text_col(@_);
}
return $self->text_col;
}
sub method_select_test {
my $self = shift;
if (@_) {
$self->select_col(@_);
}
return $self->select_col;
}
sub method_checkbox_test {
my $self = shift;
if (@_) {
$self->checkbox_col(@_);
}
return $self->checkbox_col;
}
sub inflate_column_list_comma {
sub {
[split(/,/, shift )];
}
}
sub deflate_column_list_comma {
sub {
join(',', @{(shift)} );
}
}
1;
MySchemaRS 000755 000764 000764 0 12253556454 20622 5 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib User.pm 100644 000764 000764 1007 12253556454 22234 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchemaRS package MySchemaRS::User;
use strict;
use warnings;
use base 'DBIx::Class::ResultSet';
sub is_name_available {
my ($self, $name, $row_id) = @_;
my $user = $self->find( {name => $name} );
return 0 if $user && $row_id && $user->id != $row_id; # found user with same name, and not user on stash
## do extra special-case testing
# my $name_reserved = $self->result_source->schema->resultset('NameReserved')->find( {name => $name} );
# return 0 if $name_reserved;
return 0 if $name eq 'xxx';
return 1;
}
1;
Address.pm 100644 000764 000764 1015 12253556454 22435 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::Address;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("address");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
user => { data_type => "INTEGER", is_nullable => 0 },
my_label => { data_type => "TEXT", is_nullable => 1 },
address => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( user => 'MySchema::User' );
1;
HasMany.pm 100644 000764 000764 714 12253556454 22375 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::HasMany;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("has_many");
__PACKAGE__->add_columns(
user => { data_type => "INTEGER", is_nullable => 0 },
key => { data_type => "TEXT", is_nullable => 0 },
value => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("user", "key");
__PACKAGE__->belongs_to( user => 'MySchema::User' );
1;
Manager.pm 100644 000764 000764 622 12253556454 22405 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::Manager;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("manager");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
name => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many( bands => 'MySchema::Band', 'manager' );
1;
TwoNote.pm 100644 000764 000764 747 12253556454 22442 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::TwoNote;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("two_note");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
two_note_id => { data_type => "INTEGER", is_nullable => 0 },
note => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("two_note_id");
__PACKAGE__->belongs_to( id => 'MySchema::Master', { id => 'id' } );
1;
Schedule.pm 100644 000764 000764 1144 12253556454 22607 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::Schedule;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ InflateColumn::DateTime Core /);
__PACKAGE__->table("schedule");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
master => { data_type => "INTEGER", is_nullable => 0 },
date => { data_type => "DATETIME", is_nullable => 0 },
note => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( master => 'MySchema::Master' );
__PACKAGE__->has_many( tasks => 'MySchema::Task', 'schedule' );
1;
UserBand.pm 100644 000764 000764 1116 12253556454 22555 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/MySchema package MySchema::UserBand;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("user_band");
__PACKAGE__->add_columns(
user => {
data_type => "INTEGER",
is_nullable => 0,
},
band => {
data_type => "INTEGER",
is_nullable => 0,
},
rating => {
data_type => "INTEGER",
is_nullable => 1,
}
);
__PACKAGE__->set_primary_key( "user", "band" );
__PACKAGE__->belongs_to( "user", "MySchema::User" );
__PACKAGE__->belongs_to( "band", "MySchema::Band" );
1;
create 000755 000764 000764 0 12253556454 21270 5 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t-aggregate basic.t 100644 000764 000764 1630 12253556454 22676 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t-aggregate/create use strict;
use warnings;
use Test::More tests => 6;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t-aggregate/create/basic.yml');
my $schema = new_schema();
# put schema on form stash
$form->stash->{schema} = $schema;
# Fake submitted form
$form->process( {
id => 1,
text_col => 'a',
password_col => 'b',
checkbox_col => 'foo',
select_col => '2',
radio_col => 'yes',
radiogroup_col => '3',
} );
{
# no resultset arg
$form->model->create;
}
{
my $row = $schema->resultset('Master')->find(1);
is( $row->text_col, 'a' );
is( $row->password_col, 'b' );
is( $row->checkbox_col, 'foo' );
is( $row->select_col, '2' );
is( $row->radio_col, 'yes' );
is( $row->radiogroup_col, '3' )
}
I18N 000755 000764 000764 0 12253556454 21211 5 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/HTMLFormFu en.pm 100644 000764 000764 243 12253556454 22270 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t/lib/HTMLFormFu/I18N package HTMLFormFu::I18N::en;
use strict;
use warnings;
use base qw( HTMLFormFu::I18N );
our %Lexicon = (
label_foo => 'Foo',
label_bar => 'Bar',
);
1;
basic.yml 100644 000764 000764 1223 12253556454 23232 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t-aggregate/create ---
auto_fieldset: 1
model_config:
resultset: Master
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Password
name: password_col
- type: Checkbox
name: checkbox_col
value: foo
- type: Select
name: select_col
options:
- [1, one]
- [2, two]
- [3, three]
- type: Radio
name: radio_col
value: yes
- type: Radio
name: radio_col
value: no
- type: Radiogroup
name: radiogroup_col
values: [1, 2, 3]
- type: Text
name: date_col
- type: Text
name: unknown_col
- type: Submit
name: submit
update 000755 000764 000764 0 12253556454 21307 5 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t-aggregate basic.yml 100644 000764 000764 1512 12253556454 23252 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t-aggregate/update ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Password
name: password_col
- type: Checkbox
name: checkbox_col
value: foo
- type: Select
name: select_col
options:
- [1, one]
- [2, two]
- [3, three]
- type: ComboBox
name: combobox_col
options:
- [1, one]
- [2, two]
- [3, three]
- type: Radio
name: radio_col
value: yes
- type: Radio
name: radio_col
value: no
- type: Radiogroup
name: radiogroup_col
values: [1, 2, 3]
- type: Checkboxgroup
name: array_col
options:
- [one]
- [two]
- [three]
- type: Text
name: date_col
- type: Text
name: unknown_col
- type: Submit
name: submit
has_one.t 100644 000764 000764 2142 12253556454 23247 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t-aggregate/update use strict;
use warnings;
use Test::More tests => 4;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t-aggregate/update/has_one.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler rows
{
# master 1
$rs->create( { text_col => 'xxx' } );
# master 2
my $m2 = $rs->create( { text_col => 'yyy' } );
# user 1
$m2->create_related( 'user', { name => 'zzz' } );
}
# rows we're going to use
{
# master 3
my $m3 = $rs->create( { text_col => 'b' } );
# user 2
$m3->create_related( 'user', { name => 'xxx' } );
}
{
$form->process( {
"id" => 3,
"text_col" => 'a',
"user.id" => 2,
"user.name" => 'bar',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('Master')->find(3);
$form->model->update($row);
}
{
my $row = $schema->resultset('Master')->find(3);
is( $row->text_col, 'a' );
my $user = $row->user;
is( $user->id, 2 );
is( $user->name, 'bar' );
}
methods.t 100644 000764 000764 2175 12253556454 23304 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/t-aggregate/update use strict;
use warnings;
use Test::More tests => 7;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $schema = new_schema();
my $rs = $schema->resultset('Master');
{
my $form = HTML::FormFu->new;
$form->load_config_file('t-aggregate/update/methods.yml');
# Fake submitted form
$form->process( {
method_test => 'apejens',
method_checkbox_test => 1,
} );
{
my $row = $rs->new( {} );
$form->model->update($row);
}
{
my $row = $rs->find(1);
is( $row->text_col, 'apejens' );
is( $row->method_test, 'apejens' );
is( $row->checkbox_col, 1);
is( $row->method_checkbox_test, 1);
}
}
{
my $form = HTML::FormFu->new;
$form->load_config_file('t-aggregate/update/methods.yml');
$form->process({
method_test => 'apejens2',
});
my $row = $rs->find(1);
$form->model->update($row);
is( $row->text_col, 'apejens2' );
is( $row->checkbox_col, 0);
is( $row->method_checkbox_test, 0);
}
Model 000755 000764 000764 0 12253556454 21406 5 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/lib/HTML/FormFu DBIC.pm 100644 000764 000764 151063 12253556454 22653 0 ustar 00cafranks cafranks 000000 000000 HTML-FormFu-Model-DBIC-1.00/lib/HTML/FormFu/Model package HTML::FormFu::Model::DBIC;
{
$HTML::FormFu::Model::DBIC::VERSION = '1.00';
}
use strict;
use warnings;
use base 'HTML::FormFu::Model';
use HTML::FormFu::Util qw( _merge_hashes );
use List::MoreUtils qw( none notall );
use List::Util qw( first );
use Scalar::Util qw( blessed );
use Storable qw( dclone );
use Carp qw( croak );
sub options_from_model {
my ( $self, $base, $attrs ) = @_;
my $form = $base->form;
my $resultset = _get_resultset( $base, $form, $attrs );
my $source = $resultset->result_source;
my $id_col = $attrs->{id_column};
my $label_col = $attrs->{label_column};
my $condition = $attrs->{condition};
my $attributes = $attrs->{attributes} || {};
my $enum_col =
first {
lc( $base->name ) eq lc($_);
}
grep {
my $data_type = $source->column_info($_)->{data_type};
defined $data_type && $data_type =~ /enum/i
} $source->columns;
if ( defined $enum_col ) {
return map {
[ $_, $_ ]
} @{ $source->column_info($enum_col)->{extra}{list} };
}
if ( !defined $id_col ) {
($id_col) = $source->primary_columns;
}
if ( !defined $label_col ) {
# use first text column
($label_col) = grep {
my $data_type = $source->column_info($_)->{data_type};
defined $data_type && $data_type =~ /text|varchar/i
} $source->columns;
}
$label_col = $id_col if !defined $label_col;
if ( defined( my $from_stash = $attrs->{condition_from_stash} ) ) {
$condition
= $condition
? { %{$condition} }
: {}; # avoid overwriting attrs->{condition}
for my $name ( keys %$from_stash ) {
croak "config value must not be a reference" if ref $from_stash->{$name};
my $value = $form->stash->{ $from_stash->{$name} };
$condition->{$name} = $value;
}
}
# save the expanded condition for later use
$attrs->{'-condition'} = $condition if ($condition);
$attributes->{'-columns'} = [ $id_col, $label_col ];
my $result = $resultset->search( $condition, $attributes );
my @defaults = $result->all;
my $has_column = $source->has_column($label_col);
if ( $attrs->{localize_label} ) {
@defaults = map {
{ value => $_->get_column($id_col),
label_loc => $has_column ? $_->get_column($label_col) : $_->$label_col,
}
} @defaults;
}
else {
@defaults = map { [
$_->get_column($id_col),
$has_column ? $_->get_column($label_col) : $_->$label_col,
]
} @defaults;
}
return @defaults;
}
sub _get_resultset {
my ( $base, $form, $attrs ) = @_;
my $schema = $form->stash->{schema};
my $context = $form->stash->{context};
if ( defined $schema ) {
my $rs_name = $attrs->{resultset} || ucfirst $base->name;
return $schema->resultset($rs_name);
}
elsif ( defined $context && defined $attrs->{model} ) {
my $model = $context->model( $attrs->{model} );
if ( defined( my $rs = $attrs->{resultset} ) ) {
$model = $model->resultset($rs);
}
return $model;
}
elsif ( defined $context ) {
my $model = $context->model;
return $model if defined $model;
}
croak "need a schema or context";
}
sub default_values {
my ( $self, $dbic, $attrs ) = @_;
my $form = $self->form;
my $base = defined $attrs->{base} ? delete $attrs->{base} : $form;
$base = $form->get_all_element( { nested_name => $attrs->{nested_base} } )
if defined $attrs->{nested_base}
&& ( !defined $base->nested_name
|| $base->nested_name ne $attrs->{nested_base} );
_fill_in_fields( $base, $dbic );
_fill_nested( $self, $base, $dbic );
return $form;
}
# returns 0 if there is a node with nested_name set on the path from $field to $base
sub is_direct_child {
my ( $base, $field ) = @_;
while ( defined $field->parent ) {
$field = $field->parent;
return 1 if $base == $field;
return 0 if defined $field->nested_name;
}
}
# fills in values for all direct children fields of $base
sub _fill_in_fields {
my ( $base, $dbic ) = @_;
for my $field ( @{ $base->get_fields } ) {
my $name = $field->name;
my $config = $field->model_config;
next if not defined $name || $config->{accessor};
next if not is_direct_child( $base, $field );
$name = $field->original_name if $field->original_name;
my $accessor = $config->{accessor};
if ( defined $accessor ) {
$field->default( $dbic->$accessor );
}
elsif ( $dbic->can($name) ) {
my $has_col = $dbic->result_source->has_column($name);
my $has_rel = $dbic->result_source->has_relationship($name);
if ( $has_col && $has_rel ) {
# can't use direct accessor, if there's a rel of the same name
$field->default( $dbic->get_column($name) );
}
elsif ($has_col) {
$field->default( $dbic->$name );
}
elsif (
$field->multi_value
&& ($config->{default_column}
|| ( ref( $dbic->$name )
&& $dbic->$name->can('result_source') ) ) )
{
my ($col) = $config->{default_column}
|| $dbic->$name->result_source->primary_columns;
my $info = $dbic->result_source->relationship_info($name);
if ( !defined $info or $info->{attrs}{accessor} eq 'multi' ) {
my @defaults = $dbic->$name->get_column($col)->all;
$field->default( \@defaults );
}
else {
# has_one/might_have
my ($pk) = $dbic->result_source->primary_columns;
$field->default( $dbic->$name->$pk );
}
}
else {
# This field is a method expected to return the value
$field->default( $dbic->$name );
}
}
# handle {label}
if ( defined( my $label = $config->{label} ) ) {
my $has_rel = $dbic->result_source->has_relationship($label);
if ($has_rel) {
# can't use direct accessor, if there's a rel of the same name
$field->label( $dbic->get_column($label) );
}
else {
$field->label( $dbic->$label );
}
}
}
}
# loop over all child blocks with nested_name that is a method on the DBIC row
# and recurse
sub _fill_nested {
my ( $self, $base, $dbic ) = @_;
for my $block ( @{ $base->get_all_elements } ) {
next if $block->is_field && !$block->is_block;
next if !$block->can('nested_name');
my $config = $block->model_config;
# first handle {label}
if ( defined( my $label = $config->{label} ) && $block->can('label') ) {
my $has_rel = $dbic->result_source->has_relationship($label);
if ($has_rel) {
# can't use direct accessor, if there's a rel of the same name
$block->label( $dbic->get_column($label) );
}
else {
$block->label( $dbic->$label );
}
}
my $rel = $block->nested_name;
next if !defined $rel;
my $has_rel = $dbic->result_source->relationship_info($rel)
|| ( $dbic->can($rel) && $dbic->can( 'add_to_' . $rel ) )
; # many_to_many
# recursing only when $rel is a relation or non-column accessor on $dbic
next
unless $has_rel
|| ( $dbic->can($rel)
&& !$dbic->result_source->has_column($rel) );
if ( $block->is_repeatable && $block->increment_field_names ) {
# check there's a field name matching the PK
my ($pk) = $dbic->$rel->result_source->primary_columns;
next
unless grep {
$pk eq
( defined $_->original_name ? $_->original_name : $_->name )
} @{ $block->get_fields( { type => 'Hidden' } ) };
my @rows = $dbic->$rel->all;
my $count
= $config->{empty_rows}
? scalar @rows + $config->{empty_rows}
: scalar @rows;
my $blocks = $block->repeat($count);
$block->process;
for my $rep ( 0 .. $#rows ) {
default_values( $self, $rows[$rep],
{ base => $blocks->[$rep] } );
}
# set the counter field to the number of rows
if ( defined( my $param_name = $block->counter_name ) ) {
my ($field) = grep {
$param_name eq (
defined $_->original_name
? $_->original_name
: $_->name )
} @{ $base->get_fields };
$field->default($count)
if defined $field;
}
# remove 'delete' checkbox from the last repetition ?
if ( $config->{empty_rows} ) {
my $new_row_count
= $config->{empty_rows}
? $config->{empty_rows}
: 1;
my @reps = reverse @{ $block->get_elements };
for my $i ( 0 .. ( $new_row_count - 1 ) ) {
my $rep = $reps[$i];
my ($del_field)
= grep { $_->model_config->{delete_if_true} }
@{ $rep->get_fields };
if ( defined $del_field ) {
$del_field->parent->remove_element($del_field);
}
}
}
}
else {
if ( defined( my $row = $dbic->$rel ) ) {
default_values( $self, $row, { base => $block } );
}
}
}
return;
}
sub create {
my ( $self, $attrs ) = @_;
croak "invalid arguments" if @_ > 2;
my $form = $self->form;
my $base = defined $attrs->{base} ? delete $attrs->{base} : $form;
my $schema = $form->stash->{schema}
or croak 'schema required on form stash, if no row object provided';
my $resultset
= $attrs->{resultset}
|| $base->model_config->{resultset}
|| $form->model_config->{resultset}
or croak 'could not find resultset name';
$resultset = $schema->resultset($resultset);
my $dbic = $resultset->new_result( {} );
return $self->update( $dbic, { %$attrs, base => $base } );
}
sub update {
my ( $self, $dbic, $attrs ) = @_;
croak "row object missing" if !defined $dbic;
my $form = $self->form;
my $base = defined $attrs->{base} ? delete $attrs->{base} : $form;
$base = $form->get_all_element( { nested_name => $attrs->{nested_base} } )
if defined $attrs->{nested_base}
&& ( !defined $base->nested_name
|| $base->nested_name ne $attrs->{nested_base} );
my $rs = $dbic->result_source;
my @rels = $rs->relationships;
my @cols = $rs->columns;
# check for belongs_to relationships with a required foreign key
my (@belongs_to_rels, @other_rels);
foreach my $rel (@rels) {
# 'fk_columns' is set for belong_to rels in DBIx::Class::Relationship::BelongsTo
my @fk_columns = keys %{ $dbic->relationship_info($rel)->{attrs}{fk_columns} };
if (@fk_columns) {
push @belongs_to_rels, $rel;
} else {
push @other_rels, $rel;
}
}
# add belongs_to rels before insert
if (@belongs_to_rels) {
# tell _save_relationships not to update $dbic yet, just add the rels
my %attrs = ( %$attrs, no_update => 1 );
_save_relationships( $self, $base, $dbic, $form, $rs, \%attrs, \@belongs_to_rels );
}
_save_columns( $base, $dbic, $form ) or return;
$dbic->update_or_insert;
_save_relationships( $self, $base, $dbic, $form, $rs, $attrs, \@other_rels );
_save_multi_value_fields_many_to_many( $base, $dbic, $form, $attrs, \@rels,
\@cols );
_save_repeatable_many_to_many( $self, $base, $dbic, $form, $attrs, \@rels,
\@cols );
# handle non-rel, non-column, nested_base accessors.
# - this highlights a failing of the approach of iterating over
# db cols + rels - we should maybe refactor to iterate over
# form blocks and fields instead ?
for my $block ( @{ $base->get_all_elements } ) {
next if $block->is_field;
next if !$block->can('nested_name');
my $rel = $block->nested_name;
next if !defined $rel;
next unless $dbic->can($rel);
next if grep { $rel eq $_ } @cols;
next if grep { $rel eq $_ } @rels;
next if $dbic->can( "add_to_" . $rel ); # many-to-many
if ( defined( my $row = $dbic->$rel ) ) {
update( $self, $row, { base => $block } );
}
}
return $dbic;
}
sub _save_relationships {
my ( $self, $base, $dbic, $form, $rs, $attrs, $rels ) = @_;
return if $attrs->{no_follow};
for my $rel (@$rels) {
# don't follow rels to where we came from
next
if defined $attrs->{from}
&& $attrs->{from} eq $rs->related_source($rel)->result_class;
my @elements = @{ $base->get_all_elements( { nested_name => $rel } ) };
my ($block) = grep { !$_->is_field } @elements;
my ($multi_value) = grep { $_->is_field && $_->multi_value } @elements;
my ($combo) = grep { $_->isa('HTML::FormFu::Element::ComboBox') } @elements;
next if !defined $block && !defined $multi_value;
next if !$form->valid($rel);
my $params = $form->param($rel);
if ( defined $block && $block->is_repeatable ) {
# Handle has_many
_save_has_many( $self, $dbic, $form, $rs, $block, $rel, $attrs );
}
elsif ( defined $combo ) {
_save_combobox( $self, $base, $dbic, $form, $rs, $combo, $rel, $attrs );
}
elsif ( defined $block && ref $params eq 'HASH' ) {
# It seems that $dbic->$rel must be called otherwise the following
# find_related() can fail.
# However, this can die - so we're just wrapping it in an eval
eval {
$dbic->$rel;
} or $dbic->discard_changes;
my $target = $dbic->find_related( $rel, {} );
if ( !defined $target && grep { length $_ } values %$params ) {
$target = $dbic->new_related( $rel, {} );
}
next if !defined $target;
update(
$self, $target,
{ %$attrs,
base => $block,
nested_base => $rel,
from => $dbic->result_class,
} );
unless ( $dbic->$rel ) {
$dbic->$rel($target);
$dbic->update unless $attrs->{no_update};
}
}
elsif ( defined $multi_value ) {
# belongs_to, has_one or might_have relationship
my $info = $dbic->result_source->relationship_info($rel);
my @fpkey = $dbic->related_resultset($rel)
->result_source->primary_columns;
my @cond = ( %{ $info->{cond} } );
# make sure $rel is a has_one or might_have rel
# stolen from SQL/Translator/Parser/DBIx/Class
my $fk_constraint;
# Get the key information, mapping off the foreign/self markers
my @refkeys = map {/^\w+\.(\w+)$/} @cond;
my @keys = map { $info->{cond}{$_} =~ /^\w+\.(\w+)$/ }
grep { exists $info->{cond}{$_} } @cond;
#first it can be specified explicitly
if ( exists $info->{attrs}{is_foreign_key_constraint} ) {
$fk_constraint = $info->{attrs}{is_foreign_key_constraint};
}
# it can not be multi
elsif ($info->{attrs}{accessor}
&& $info->{attrs}{accessor} eq 'multi' )
{
$fk_constraint = 0;
}
# if indeed single, check if all self.columns are our primary keys.
# this is supposed to indicate a has_one/might_have...
# where's the introspection!!?? :)
else {
$fk_constraint
= not _compare_relationship_keys( \@keys, \@fpkey );
}
next if ($fk_constraint);
my $fpkey = shift @fpkey;
my ( $fkey, $skey ) = @cond;
$fkey =~ s/^foreign\.//;
$skey =~ s/^self\.//;
my $fclass = $info->{class};
croak
'The primary key and the foreign key may not be the same column in class '
. $fclass
if $fpkey eq $fkey;
croak
'multiple primary keys are not supported for has_one/might_have relationships'
if ( @fpkey > 1 );
my $schema = $dbic->result_source->schema;
# use transactions if supported by storage
$schema->txn_do(
sub {
# reset any previous items which were related to $dbic
$rs->schema->resultset($fclass)
->search( { $fkey => $dbic->$skey } )
->update( { $fkey => undef } );
# set new related item
my $updated
= $rs->schema->resultset($fclass)
->search( { $fpkey => $params } )
->update( { $fkey => $dbic->$skey } );
$schema->txn_rollback
if $updated != 1;
} );
}
}
}
sub _save_combobox {
my ( $self, $base, $dbic, $form, $rs, $combo, $rel, $attrs ) = @_;
my $select = $combo->get_field({ type => 'Select' });
my $text = $combo->get_field({ type => 'Text' });
my $select_value = $form->param( $select->nested_name );
my $text_value = $form->param( $text->nested_name );
my $target_rs = $dbic->result_source->related_source( $rel )->resultset;
my $target;
if ( defined $select_value && length $select_value ) {
my $pk_name = $combo->model_config->{select_column};
$target = $target_rs->find(
{
$pk_name => $select_value,
},
);
}
else {
my $column_name = $combo->model_config->{text_column};
$target = $target_rs->create(
{
$column_name => $text_value,
},
);
}
$dbic->set_from_related( $rel, $target );
$dbic->update;
}
# Copied from DBIx::Class::ResultSource
sub _compare_relationship_keys {
my ( $keys1, $keys2 ) = @_;
# Make sure every keys1 is in keys2
my $found;
foreach my $key (@$keys1) {
$found = 0;
foreach my $prim (@$keys2) {
if ( $prim eq $key ) {
$found = 1;
last;
}
}
last unless $found;
}
# Make sure every key2 is in key1
if ($found) {
foreach my $prim (@$keys2) {
$found = 0;
foreach my $key (@$keys1) {
if ( $prim eq $key ) {
$found = 1;
last;
}
}
last unless $found;
}
}
return $found;
}
sub _save_has_many {
my ( $self, $dbic, $form, $rs, $block, $rel, $attrs ) = @_;
return unless $block->increment_field_names;
# check there's a field name matching the PK
my ($pk) = $rs->related_source($rel)->primary_columns;
return
unless grep { $_->original_name eq $pk }
@{ $block->get_fields( { type => 'Hidden' } ) };
my @blocks = @{ $block->get_elements };
my $max = $#blocks;
my $config = $block->model_config;
my $new_rows_max = $config->{new_rows_max} || $config->{empty_rows} || 0;
my $new_rows_counter = 0;
# iterate over blocks, not rows
# new rows might have been created in the meantime
for my $i ( 0 .. $max ) {
my $rep = $blocks[$i];
# find PK field
my ($pk_field)
= grep { $_->original_name eq $pk }
@{ $rep->get_fields( { type => 'Hidden' } ) };
next if !defined $pk_field;
my $value = $form->param_value( $pk_field->nested_name );
my $row;
if (( !defined $value || $value eq '' )
&& ( $new_rows_max
&& ( ++$new_rows_counter <= $new_rows_max ) ) )
{
# insert a new row
$row = _insert_has_many( $dbic, $form, $config, $rep, $rel,
$pk_field );
next if !defined $row;
}
elsif ( !defined $value || $value eq '' ) {
next;
}
else {
$row = $dbic->find_related( $rel, $value );
}
next if !defined $row;
# should we delete the row?
next if _delete_has_many( $form, $row, $rep );
update(
$self, $row,
{ %$attrs,
base => $rep,
repeat_base => $rel,
from => $dbic->result_class,
} );
}
}
sub _insert_has_many {
my ( $dbic, $form, $config, $repetition, $rel, $pk_field ) = @_;
return
if !_can_insert_new_row( $dbic, $form, $config, $repetition, $rel,
$pk_field );
my $row = $dbic->new_related( $rel, {} );
return $row;
}
sub _can_insert_new_row {
my ( $dbic, $form, $config, $repetition, $rel, $pk_field ) = @_;
my @rep_fields = @{ $repetition->get_fields };
my $pk_name = $pk_field->nested_name;
my @constraints = grep { $_->when->{field} eq $pk_name }
grep { defined $_->when }
map { @{ $_->get_constraints( { type => 'Required' } ) } } @rep_fields;
my @required_fields;
if (@constraints) {
# if there are any Required constraints whose 'when' clause points to
# the PK field - check that all these fields are filled in - as
# the PK value is missing on new reps, so the constraint won't have run
return
if notall { defined && length }
map { $form->param_value( $_->nested_name ) }
map { $_->parent } @constraints;
}
else {
# otherwise, just check at least 1 field that matches either a column
# name or an accessor, is filled in
my $result_source = $dbic->$rel->result_source;
# only create a new record if (read from bottom)...
return
if none { defined && length }
map { $form->param_value( $_->nested_name ) }
grep {
$result_source->has_column( $_->original_name )
|| $result_source->can( $_->original_name )
}
grep { defined $_->original_name } @rep_fields;
}
return 1;
}
sub _delete_has_many {
my ( $form, $row, $rep ) = @_;
my ($del_field)
= grep { $_->model_config->{delete_if_true} } @{ $rep->get_fields };
return if !defined $del_field;
my $nested_name = $del_field->nested_name;
return
unless $form->valid($nested_name)
&& $form->param_value($nested_name);
$row->delete if ( $row->in_storage );
return 1;
}
sub _fix_value {
my ( $dbic, $col, $value, $field, ) = @_;
my $col_info = $dbic->column_info($col);
my $is_nullable = $col_info->{is_nullable} || 0;
my $data_type = $col_info->{data_type} || '';
if ( defined $value ) {
if ( ( ( $is_nullable
&& $data_type =~ m/^timestamp|date|int|float|numeric/i
) or $field->model_config->{null_if_empty} )
# comparing to '' does not work for inflated objects
&& !ref $value
&& $value eq ''
)
{
$value = undef;
}
}
if ( !defined $value
&& defined $field
&& $field->isa('HTML::FormFu::Element::Checkbox')
&& !$is_nullable )
{
$value = 0;
}
return $value;
}
sub _save_columns {
my ( $base, $dbic, $form ) = @_;
for my $field ( @{ $base->get_fields }, ) {
next if not is_direct_child( $base, $field );
my $config = $field->model_config;
next if $config->{delete_if_true};
next if $config->{read_only};
my $name = $field->name;
$name = $field->original_name if $field->original_name;
my $accessor = $config->{accessor} || $name;
next if not defined $accessor;
my $value = ( $dbic->result_source->has_column($accessor)
and exists $dbic->result_source->column_info($accessor)->{is_array} )
? $form->param_array( $field->nested_name )
: $form->param_value( $field->nested_name ) ;
next
if $config->{ignore_if_empty}
&& ( !defined $value || $value eq "" );
my ($pk) = $dbic->result_source->primary_columns;
# don't set primary key to null or '' - for Pg SERIALs
next if ( $name eq $pk ) && !( defined $value && length $value );
if ( $config->{delete_if_empty}
&& ( !defined $value || !length $value ) )
{
$dbic->discard_changes if $dbic->is_changed;
$dbic->delete if $dbic->in_storage;
return;
}
if ( $dbic->result_source->has_column($accessor) ) {
$value = _fix_value( $dbic, $accessor, $value, $field );
}
elsif ( $field->isa('HTML::FormFu::Element::Checkbox') ) {
# We are a checkbox.
unless ( defined $value ) {
$value = 0;
}
}
if ( !$config->{accessor}
and $dbic->result_source->has_relationship($accessor)
and $dbic->result_source->has_column($accessor) )
{
$dbic->set_column( $accessor, $value );
}
elsif (
$dbic->can($accessor)
# and $accessor is not a has_one or might_have rel where the foreign key is on the foreign table
and !$dbic->result_source->relationship_info($accessor) )
{
$dbic->$accessor($value);
}
else {
# We should just ignore
#croak "cannot call $accessor on $dbic";
}
}
# for values inserted by add_valid - and not correlated to any field in the form
my $parent = $base;
do {
return 1 if defined $parent->nested_name;
$parent = $parent->parent;
} until ( !defined $parent );
for my $valid ( $form->valid ) {
next if @{ $base->get_fields( name => $valid ) };
next if not $dbic->can($valid);
my $value = $form->param_value($valid);
$dbic->$valid($value);
}
return 1;
}
sub _save_multi_value_fields_many_to_many {
my ( $base, $dbic, $form, $attrs, $rels, $cols ) = @_;
my @fields = grep {
( defined $attrs->{nested_base} && defined $_->parent->nested_name )
? $_->parent->nested_name eq $attrs->{nested_base}
: !$_->nested
}
grep { $_->multi_value }
grep { defined $_->name } @{ $base->get_fields };
for my $field (@fields) {
my $name = $field->name;
next if grep { $name eq $_ } @$rels, @$cols;
if ( $dbic->can($name) ) {
my $related = $dbic->$name;
next if !blessed($related) || !$related->can('result_source');
my $nested_name = $field->nested_name;
next if $form->has_errors($nested_name);
my @values = $form->param_list($nested_name);
my @rows;
my $config = $field->model_config;
next if $config->{read_only};
my ($pk) = $config->{default_column}
|| $related->result_source->primary_columns;
if (@values) {
$pk = "me.$pk" unless $pk =~ /\./;
@rows = $related->result_source->resultset->search( {
%{ $config->{condition} || {} },
$pk => { -in => \@values } } )->all;
}
if ( $config->{additive} ) {
$pk =~ s/^.*\.//;
my $set_method = "add_to_$name";
my $remove_method = "remove_from_$name";
foreach my $row (@rows) {
$dbic->$remove_method($row);
$dbic->$set_method( $row, $config->{link_values} );
}
}
else {
# check if there is a restricting condition on here
# if so life is more complex
my $condition = $config->{'-condition'};
if ($condition) {
my $set_method = "add_to_$name";
my $remove_method = "remove_from_$name";
foreach ( $dbic->$name->search($condition)->all ) {
$dbic->$remove_method($_);
}
foreach my $row (@rows) {
$dbic->$set_method( $row, $config->{link_values} );
}
}
else {
my $set_method = "set_$name";
$dbic->$set_method( \@rows, $config->{link_values} );
}
}
}
}
}
sub _save_repeatable_many_to_many {
my ( $self, $base, $dbic, $form, $attrs, $rels, $cols ) = @_;
my @blocks
= grep { !$_->is_field && $_->is_repeatable && $_->increment_field_names }
@{ $base->get_all_elements };
for my $block (@blocks) {
my $rel = $block->nested_name;
next if !defined $rel;
next if grep { $rel eq $_ } @$rels, @$cols;
if ( $dbic->can($rel) ) {
# check there's a field name matching the PK
my ($pk) = $dbic->$rel->result_source->primary_columns;
my @blocks = @{ $block->get_elements };
my $max = $#blocks;
# iterate over blocks, not rows
# new rows might have been created in the meantime
for my $i ( 0 .. $max ) {
my $rep = $blocks[$i];
# find PK field
my ($pk_field)
= grep { $_->original_name eq $pk }
@{ $rep->get_fields( { type => 'Hidden' } ) };
next if !defined $pk_field;
my $value = $form->param_value( $pk_field->nested_name );
my $row;
my $is_new;
my $config = $block->model_config;
my $new_rows_max
= $config->{new_rows_max}
|| $config->{empty_rows}
|| 0;
my $new_rows_counter = 0;
if (( !defined $value || $value eq '' )
&& ( $new_rows_max
&& ( ++$new_rows_counter <= $new_rows_max ) ) )
{
# insert a new row
$row = _insert_many_to_many( $dbic, $form, $config, $rep,
$rel, $pk_field );
next if !defined $row;
$is_new = 1;
}
elsif ( !defined $value || $value eq '' ) {
next;
}
else {
$row = $dbic->$rel->find($value);
}
next if !defined $row;
# should we delete the row?
next if _delete_many_to_many( $form, $dbic, $row, $rel, $rep );
update(
$self, $row,
{ %$attrs,
base => $rep,
repeat_base => $rel,
from => $dbic->result_class,
} );
if ($is_new) {
# new rows need to be related
my $add_method = "add_to_$rel";
$dbic->$add_method($row);
}
}
}
}
return;
}
sub _insert_many_to_many {
my ( $dbic, $form, $config, $repetition, $rel, $pk_field ) = @_;
return
if !_can_insert_new_row( $dbic, $form, $config, $repetition, $rel,
$pk_field );
my $row = $dbic->$rel->new( {} );
# add_to_* will be called later, after update is called on this row
return $row;
}
sub _delete_many_to_many {
my ( $form, $dbic, $row, $rel, $rep ) = @_;
my ($del_field)
= grep { $_->model_config->{delete_if_true} } @{ $rep->get_fields };
return if !defined $del_field;
my $nested_name = $del_field->nested_name;
return
unless $form->valid($nested_name)
&& $form->param_value($nested_name);
my $remove = "remove_from_$rel";
$dbic->$remove($row);
return 1;
}
1;
__END__
=head1 NAME
HTML::FormFu::Model::DBIC - Integrate HTML::FormFu with DBIx::Class
=head1 SYNOPSIS
Example of typical use in a Catalyst controller:
sub edit : Chained {
my ( $self, $c ) = @_;
my $form = $c->stash->{form};
my $book = $c->stash->{book};
if ( $form->submitted_and_valid ) {
# update dbic row with submitted values from form
$form->model->update( $book );
$c->response->redirect( $c->uri_for('view', $book->id) );
return;
}
elsif ( !$form->submitted ) {
# use dbic row to set form's default values
$form->model->default_values( $book );
}
return;
}
=head1 SETUP
For the form object to be able to access your L schema, it needs
to be placed on the form stash, with the name C.
This is easy if you're using L, as you can
set this up to happen in your Catalyst app's config file.
For example, if your model is named C, you would set this
(in L format):
schema Corp
Or if your app's config file is in L format:
'Controller::HTML::FormFu':
model_stash:
schema: Corp
=head1 METHODS
=head2 default_values
Arguments: $dbic_row, [\%config]
Return Value: $form
$form->model->default_values( $dbic_row );
Set a form's default values from the database, to allow a user to edit them.
=head2 update
Arguments: [$dbic_row], [\%config]
Return Value: $dbic_row
$form->model->update( $dbic_row );
Update the database with the submitted form values.
=head2 create
Arguments: [\%config]
Return Value: $dbic_row
my $dbic_row = $form->model->create( {resultset => 'Book'} );
Like L, but doesn't require a C<$dbic_row> argument.
You need to ensure the DBIC schema is available on the form stash - see
L for an example config.
The C must be set either in the method arguments, or the form or
block's C.
An example of setting the ResultSet name on a Form:
---
model_config:
resultset: FooTable
elements:
# [snip]
=head2 options_from_model
Populates a multi-valued field with values from the database.
This method should not be called directly, but is called for you during
C<< $form->process >> by fields that inherit from
L. This includes:
=over
=item L
=item L
=item L
=item L
=back
To use you must set the appropriate C on the element C:
element:
- type: Select
name: foo
model_config:
resultset: TableClass
=head1 BUILDING FORMS
=head2 single table
To edit the values in a row with no related rows, the field names simply have
to correspond to the database column names.
For the following DBIx::Class schema:
package MySchema::Book;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("book");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER" },
title => { data_type => "TEXT" },
author => { data_type => "TEXT" },
blurb => { data_type => "TEXT" },
);
__PACKAGE__->set_primary_key("id");
1;
A suitable form for this might be:
elements:
- type: Text
name: title
- type: Text
name: author
- type: Textarea
name: blurb
=head2 might_have and has_one relationships
Set field values from a related row with a C or C
relationship by placing the fields within a
L (or any element that inherits from
Block, such as L