HTML-FormFu-Model-DBIC-2.03/0000775000175100017520000000000013262760616013575 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/dist.ini0000644000175100017520000000353713262760616015247 0ustar carlcarlname = HTML-FormFu-Model-DBIC author = Carl Franks license = Perl_5 copyright_holder = Carl Franks copyright_year = 2016 [Prereqs] perl = 5.008001 DBD::SQLite = 0 DBIx::Class = 0.08108 HTML::FormFu = 2.00 List::MoreUtils = 0 MooseX::Attribute::Chained = 1.0.2 Storable = 0 Task::Weaken = 0 ; make sure Scalar::Util has weaken() [Prereqs / TestRequires] DateTime::Format::SQLite = 0 Locale::Maketext = 0 SQL::Translator = 0.11016 ; for $schema->deploy() Test::More = 0.99 [Prereqs / DevelopRequires] Test::Pod = 0 ;; -- ;; -- Sets of additional tests we want to do as part of release [Test::Perl::Critic] [MetaTests] ;; [PodCoverageTests] ; Currently we comprehensively fail these [OurPkgVersion] [PodVersion] [Test::Kwalitee] [Test::EOL] finder = :InstallModules ; prevents test inputs being flagged [Test::PAUSE::Permissions] ; if doing a release make sure we have PAUSE perms ;; -- Additional information [GithubMeta] ; Grab the repo metadata [NextRelease] ; Mark up the next release in changes ;; -- Additional git [Git::GatherDir] [Git::NextVersion] ; Get the next version tag from git [Git::CheckFor::CorrectBranch] ; ensure on master branch for release [Git::Remote::Check] ; ensure our branch is ahead of remote ;; -- We base the release stuff on the starter module, and tweak a bit [@Starter] -remove = GatherDir ; this is replaced by [Git::GatherDir] ReadmeAnyFromPod.source_filename = lib/HTML/FormFu/Model/DBIC.pm [ReadmeAnyFromPod / Pod_Readme] type = pod location = root ; do not include pod readmes in the build! [@Git] changelog = Changes allow_dirty = dist.ini allow_dirty = README.pod allow_dirty = Changes commit_msg = v%v%t - %d%n%n%c tag_format = v%v%t ; see Git::Tag tag_message = v%v%t - %d ; see Git::TagHTML-FormFu-Model-DBIC-2.03/MANIFEST0000644000175100017520000001673513262760616014740 0ustar carlcarl# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.011. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/HTML/FormFu/Constraint/DBIC/Unique.pm lib/HTML/FormFu/Model/DBIC.pm t/00-report-prereqs.dd t/00-report-prereqs.t t/constraints/dbic_unique.t t/constraints/dbic_unique.yml t/constraints/dbic_unique_column.yml t/constraints/dbic_unique_id_field.yml t/constraints/dbic_unique_method.yml t/constraints/dbic_unique_others.yml t/constraints/dbic_unique_repeatable_id_field.t t/constraints/dbic_unique_repeatable_id_field.yml t/create/basic.t t/create/basic.yml t/default_values/basic.t t/default_values/basic.yml t/default_values/basic_nested.t t/default_values/basic_nested.yml t/default_values/belongs_to_lookup_table.t t/default_values/belongs_to_lookup_table.yml t/default_values/belongs_to_lookup_table_combobox.t t/default_values/belongs_to_lookup_table_combobox.yml t/default_values/empty_rows_zero.t t/default_values/empty_rows_zero.yml t/default_values/has_many_combobox.t t/default_values/has_many_combobox.yml t/default_values/has_many_repeatable.t t/default_values/has_many_repeatable.yml t/default_values/has_many_repeatable_delete_true.t t/default_values/has_many_repeatable_delete_true.yml t/default_values/has_many_repeatable_label.t t/default_values/has_many_repeatable_label.yml t/default_values/has_many_repeatable_nested.t t/default_values/has_many_repeatable_nested.yml t/default_values/has_many_repeatable_new.t t/default_values/has_many_repeatable_new.yml t/default_values/has_many_select.t t/default_values/has_many_select.yml t/default_values/has_one.t t/default_values/has_one.yml t/default_values/has_one_nested.t t/default_values/has_one_nested.yml t/default_values/label.t t/default_values/label.yml t/default_values/many_to_many-has_many.t t/default_values/many_to_many-has_many.yml t/default_values/many_to_many_checkboxgroup.t t/default_values/many_to_many_checkboxgroup.yml t/default_values/many_to_many_repeatable.t t/default_values/many_to_many_repeatable.yml t/default_values/many_to_many_repeatable_nested.t t/default_values/many_to_many_repeatable_nested.yml t/default_values/many_to_many_repeatable_new.t t/default_values/many_to_many_repeatable_new.yml t/default_values/many_to_many_select.t t/default_values/many_to_many_select.yml t/default_values/many_to_many_select_nested.t t/default_values/many_to_many_select_nested.yml t/default_values/methods.t t/default_values/methods.yml t/default_values/might_have.t t/default_values/might_have.yml t/default_values/might_have_missing.t t/default_values/multi_label.t t/default_values/multi_label.yml t/default_values/nested_name_accessor.t t/default_values/nested_name_accessor.yml t/default_values/opt_accessor.t t/default_values/opt_accessor.yml t/default_values/opt_accessor_nested.t t/default_values/opt_accessor_nested.yml 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 t/options_from_model/belongs_to.t t/options_from_model/belongs_to.yml t/options_from_model/belongs_to_combobox.t t/options_from_model/belongs_to_combobox.yml t/options_from_model/belongs_to_config_zero.t t/options_from_model/belongs_to_config_zero.yml t/options_from_model/belongs_to_config_zero_combobox.t t/options_from_model/belongs_to_config_zero_combobox.yml t/options_from_model/belongs_to_localize_label.t t/options_from_model/belongs_to_localize_label.yml t/options_from_model/condition_from_stash.t t/options_from_model/condition_from_stash.yml t/options_from_model/condition_from_stash_combobox.t t/options_from_model/condition_from_stash_combobox.yml t/options_from_model/condition_from_stash_combobox_complex.t t/options_from_model/condition_from_stash_complex.t t/options_from_model/condition_from_stash_expand.t t/options_from_model/condition_from_stash_expand.yml t/options_from_model/constraint_autoset.t t/options_from_model/constraint_autoset.yml t/options_from_model/enum_select.t t/options_from_model/enum_select.yml t/options_from_model/has_many_repeatable_select.t t/options_from_model/has_many_repeatable_select.yml t/options_from_model/many_to_many_select.t t/options_from_model/many_to_many_select.yml t/options_from_model/many_to_many_select_restricted.t t/options_from_model/many_to_many_select_restricted.yml t/update/add_valid.t t/update/basic.yml t/update/basic_create.t t/update/basic_update.t t/update/belongs_to.t t/update/belongs_to_combobox.t t/update/belongs_to_create.t t/update/belongs_to_create_required.t t/update/belongs_to_lookup_table_combobox.t t/update/belongs_to_lookup_table_combobox.yml t/update/belongs_to_select.t t/update/belongs_to_select.yml t/update/belongs_to_select_two.yml t/update/column_without_field.t t/update/column_without_field.yml t/update/has_many_repeatable.t t/update/has_many_repeatable.yml t/update/has_many_repeatable_delete_true.t t/update/has_many_repeatable_delete_true.yml t/update/has_many_repeatable_many_new.t t/update/has_many_repeatable_many_new.yml t/update/has_many_repeatable_many_new_exceed_max.t t/update/has_many_repeatable_new.t t/update/has_many_repeatable_new.yml t/update/has_many_repeatable_new_date.t t/update/has_many_repeatable_new_date.yml t/update/has_many_repeatable_new_dependon.t t/update/has_many_repeatable_new_dependon.yml t/update/has_many_repeatable_new_empty.t t/update/has_many_repeatable_new_implicit.t t/update/has_many_repeatable_new_implicit.yml t/update/has_many_repeatable_new_required_when.t t/update/has_many_repeatable_new_required_when.yml t/update/has_one.t t/update/has_one.yml t/update/has_one_create.t t/update/has_one_no_id.t t/update/has_one_no_id.yml t/update/has_one_select.t t/update/has_one_select.yml t/update/ignore_if_empty.t t/update/ignore_if_empty.yml t/update/many_to_many-has_many.t t/update/many_to_many_checkboxgroup.t t/update/many_to_many_checkboxgroup.yml t/update/many_to_many_checkboxgroup_read_only.t t/update/many_to_many_checkboxgroup_read_only.yml t/update/many_to_many_checkboxgroup_restricted.t t/update/many_to_many_checkboxgroup_restricted.yml t/update/many_to_many_checkboxgroup_unselected.t t/update/many_to_many_repeatable.t t/update/many_to_many_repeatable.yml t/update/many_to_many_repeatable_new.t t/update/many_to_many_repeatable_new.yml t/update/many_to_many_select.t t/update/many_to_many_select.yml t/update/many_to_many_select_additive.yml t/update/many_to_many_select_unselected.t t/update/methods.t t/update/methods.yml t/update/might_have.t t/update/might_have.yml t/update/might_have_create.t t/update/might_have_delete_if_empty.t t/update/might_have_delete_if_empty.yml t/update/nested.yml t/update/nested_create.t t/update/nested_create_checkbox.t t/update/nested_name_accessor.t t/update/nested_repeatable_write.t t/update/nested_repeatable_write.yml t/update/null_if_empty.t t/update/null_if_empty.yml t/update/opt_accessor.t t/update/opt_accessor.yml t/update/opt_accessor_nested.t t/update/opt_accessor_nested.yml t/update/unchecked_not_null_checkbox.t t/x_roundtrip/checkbox.yml t/x_roundtrip/checkbox_false2true.t t/x_roundtrip/checkbox_true2false.t xt/author/00-compile.t xt/author/critic.t xt/author/eol.t xt/author/pod-syntax.t xt/release/distmeta.t xt/release/kwalitee.t xt/release/pause-permissions.t HTML-FormFu-Model-DBIC-2.03/t/0000775000175100017520000000000013262760616014040 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/constraints/0000775000175100017520000000000013262760616016407 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_repeatable_id_field.yml0000644000175100017520000000063413262760616025425 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: count - type: Repeatable nested_name: user counter_name: count model_config: new_rows_max: 1 elements: - type: Hidden name: id - name: name constraints: - type: DBIC::Unique resultset: User id_field: user.id - name: title - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_method.yml0000644000175100017520000000047713262760616022767 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name constraints: - Required - type: DBIC::Unique resultset: User method_name: is_name_available self_stash_key: user - type: Text name: title - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique.yml0000644000175100017520000000037313262760616021422 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name constraints: - Required - type: DBIC::Unique resultset: User - type: Text name: title - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_repeatable_id_field.t0000644000175100017520000000327213262760616025070 0ustar carlcarluse strict; use warnings; use Test::More tests => 8; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $schema = new_schema(); my $rs = $schema->resultset('User'); # Pre-existing rows $rs->create( { id => 1, name => 'a', title => 'b', } ); $rs->create( { id => 2, name => 'e', title => 'f', } ); # my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/dbic_unique_repeatable_id_field.yml'); $form->stash->{'schema'} = $schema; # not valid # try updating row#1 with the same name as row#2 # fails Unique { $form->process( { 'user_1.id' => 1, 'user_1.name' => 'e', 'user_1.title' => 'title', } ); ok( !$form->submitted_and_valid ); ok( $form->has_errors('user_1.name') ); like( $form->get_field({ nested_name => 'user_1.name' }), qr/Value already exists/i ); } # valid # update row#1 with the same name it already has { $form->process( { 'user_1.id' => 1, 'user_1.name' => 'a', 'user_1.title' => 'title', } ); ok( $form->submitted_and_valid ); } # not valid # try creating a new row with the same name as row#1 { $form->process( { 'user_1.id' => '', 'user_1.name' => 'a', 'user_1.title' => 'title', } ); ok( !$form->submitted_and_valid ); ok( $form->has_errors('user_1.name') ); like( $form->get_field({ nested_name => 'user_1.name' }), qr/Value already exists/i ); } # valid # create new row with a unique name { $form->process( { 'user_1.id' => '', 'user_1.name' => 'snowflake', 'user_1.title' => 'title', } ); ok( $form->submitted_and_valid ); } HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_others.yml0000644000175100017520000000042413262760616023003 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name constraints: - Required - type: DBIC::Unique resultset: User others: title - type: Text name: title - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique.t0000644000175100017520000001014013262760616021055 0ustar carlcarluse strict; use warnings; use Test::More tests => 15; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $schema = new_schema(); my $rs = $schema->resultset('User'); # Pre-existing row to check against. $rs->create( { id => '1', name => 'a', title => 'b', } ); # Second row to check against for method_name with record on stash $rs->create( { name => 'e', title => 'f', } ); # Basic form. { my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/dbic_unique.yml'); $form->stash->{'schema'} = $schema; $form->process( { 'name' => 'a', 'title' => 'c', } ); ok( !$form->submitted_and_valid ); is_deeply( [ 'name', ], [ $form->has_errors ], ); } # Form where DB column differs from form field name. { my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/dbic_unique_column.yml'); $form->stash->{'schema'} = $schema; $form->process( { 'username' => 'a', 'title' => 'c', } ); ok( !$form->submitted_and_valid ); is_deeply( [ 'username', ], [ $form->has_errors ], ); } # Form tracking a multi-column unique key (name+title). { my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/dbic_unique_others.yml'); $form->stash->{'schema'} = $schema; $form->process( { 'name' => 'a', 'title' => 'c', } ); ok( $form->submitted_and_valid ); $form->process( { 'name' => 'a', 'title' => 'b', } ); ok( !$form->submitted_and_valid ); is_deeply( [ 'name', ], [ $form->has_errors ], ); } # Form using a method_name to determine uniqueness with record on stash (is_name_available). { my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/dbic_unique_method.yml'); my $user = $schema->resultset('User')->find( {name => 'a'} ); $form->stash->{'schema'} = $schema; $form->stash->{'user'} = $user; $form->process( { 'name' => 'a', 'title' => 'b', } ); ok( $form->submitted_and_valid ); $form->process( { 'name' => 'c', 'title' => 'd', } ); ok( $form->submitted_and_valid ); $form->process( { 'name' => 'e', 'title' => 'f', } ); } # Form where id_field defined { my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/dbic_unique_id_field.yml'); $form->stash->{'schema'} = $schema; # not uniq id - not uniq name => ok (no changes) $form->process( { 'id' => '1', 'name' => 'a', 'title' => 'c', } ); ok( $form->submitted_and_valid ); # no id - uniq name => ok $form->process( { 'name' => 'c', 'title' => 'b', } ); ok( $form->submitted_and_valid ); # not uniq id - uniq name => ok $form->process( { 'id' => '1', 'name' => 'c', 'title' => 'b', } ); ok( $form->submitted_and_valid ); # no id - not uniq name -> error $form->process( { 'name' => 'a', 'title' => 'b', } ); ok( !$form->submitted_and_valid ); # uniq id - not uniq name => error $form->process( { 'id' => '2', 'name' => 'a', 'title' => 'b', } ); ok( !$form->submitted_and_valid ); is_deeply( [ 'name', ], [ $form->has_errors ], ); } HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_id_field.yml0000644000175100017520000000042113262760616023233 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name constraints: - Required - type: DBIC::Unique resultset: User id_field: id - type: Text name: title - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_column.yml0000644000175100017520000000042713262760616022777 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: username constraints: - Required - type: DBIC::Unique resultset: User column: name - type: Text name: title - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/x_roundtrip/0000775000175100017520000000000013262760616016415 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/x_roundtrip/checkbox_false2true.t0000644000175100017520000000222013262760616022516 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $config_file = 't/x_roundtrip/checkbox.yml'; my $schema = new_schema(); my $rs = $schema->resultset('Master'); # filler row $rs->create( { text_col => 'filler', } ); # row we're going to use # column value starts off false $rs->create( { checkbox_col => 0, } ); # default_values() { my $form = HTML::FormFu->new; $form->load_config_file( $config_file ); my $row = $rs->find(2); $form->model->default_values($row); # check field value my $checkbox = $form->get_field('checkbox_col'); is( $checkbox->default, '0' ); my $expected_xhtml = q{}; like( "$checkbox", qr/\Q$expected_xhtml\E/ ); } # update() # value is submitted { my $form = HTML::FormFu->new; $form->load_config_file( $config_file ); $form->process({ id => '2', checkbox_col => '1', }); my $row = $rs->find(2); $form->model->update($row); # check database is( $row->checkbox_col, '1' ); } HTML-FormFu-Model-DBIC-2.03/t/x_roundtrip/checkbox_true2false.t0000644000175100017520000000222313262760616022521 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $config_file = 't/x_roundtrip/checkbox.yml'; my $schema = new_schema(); my $rs = $schema->resultset('Master'); # filler row $rs->create( { text_col => 'filler', } ); # row we're going to use # column value starts off true $rs->create( { checkbox_col => 1, } ); # default_values() { my $form = HTML::FormFu->new; $form->load_config_file( $config_file ); my $row = $rs->find(2); $form->model->default_values($row); # check field value my $checkbox = $form->get_field('checkbox_col'); is( $checkbox->default, '1' ); my $expected_xhtml = q{}; like( "$checkbox", qr/\Q$expected_xhtml\E/ ); } # update() # value isn't submitted, so it becomes false { my $form = HTML::FormFu->new; $form->load_config_file( $config_file ); $form->process({ id => 2, }); my $row = $rs->find(2); $form->model->update($row); # check database is( $row->checkbox_col, '0' ); } HTML-FormFu-Model-DBIC-2.03/t/x_roundtrip/checkbox.yml0000644000175100017520000000011413262760616020720 0ustar carlcarl--- elements: - name: id - type: Checkbox name: checkbox_col HTML-FormFu-Model-DBIC-2.03/t/00-report-prereqs.dd0000644000175100017520000000427313262760616017564 0ustar carlcarldo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0' } }, 'develop' => { 'requires' => { 'File::Spec' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Test::CPAN::Meta' => '0', 'Test::EOL' => '0', 'Test::Kwalitee' => '1.21', 'Test::More' => '0.88', 'Test::PAUSE::Permissions' => '0', 'Test::Perl::Critic' => '0', 'Test::Pod' => '1.41' } }, 'runtime' => { 'requires' => { 'DBD::SQLite' => '0', 'DBIx::Class' => '0.08108', 'HTML::FormFu' => '2.00', 'List::MoreUtils' => '0', 'MooseX::Attribute::Chained' => 'v1.0.2', 'Storable' => '0', 'Task::Weaken' => '0', 'perl' => '5.008001' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'DateTime::Format::SQLite' => '0', 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'Locale::Maketext' => '0', 'SQL::Translator' => '0.11016', 'Test::More' => '0.99' } } }; $x; }HTML-FormFu-Model-DBIC-2.03/t/default_values/0000775000175100017520000000000013262760616017043 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/default_values/might_have_missing.t0000644000175100017520000000230713262760616023074 0ustar carlcarluse 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/default_values/might_have.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); my $note_rs = $schema->resultset('Note'); { # insert some entries we'll ignore, so our rels don't have same ids # test id 1 my $t1 = $rs->new_result( { text_col => 'xxx' } ); $t1->insert; # test id 2 my $t2 = $rs->new_result( { text_col => 'yyy' } ); $t2->insert; # note id 1 my $n1 = $t2->new_related( 'note', { note => 'zzz' } ); $n1->insert; # should get test id 3 my $master = $rs->new_result( { text_col => 'a', } ); $master->insert; # no note } { my $row = $rs->find(3); $form->model->default_values($row); is( $form->get_field('id')->render_data->{value}, 3 ); is( $form->get_field('text_col')->render_data->{value}, 'a' ); my $block = $form->get_all_element( { nested_name => 'note' } ); is( $block->get_field('id')->render_data->{value}, undef ); is( $block->get_field('note')->render_data->{value}, undef ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_label.yml0000644000175100017520000000057213262760616024712 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count elements: - type: Hidden name: id - type: Text name: address model_config: label: my_label - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/nested_name_accessor.yml0000644000175100017520000000014613262760616023731 0ustar carlcarl--- elements: - name: name - type: Block nested_name: foo elements: - name: value HTML-FormFu-Model-DBIC-2.03/t/default_values/has_one.yml0000644000175100017520000000033713262760616021203 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Block nested_name: user elements: - type: Text name: name - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/belongs_to_lookup_table.t0000644000175100017520000000117413262760616024124 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/belongs_to_lookup_table.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); # filler row $rs->create( { text_col => 'filler', } ); # row we're going to use $rs->create( { text_col => 'a', type_id => 3, } ); { my $row = $rs->find(2); $form->model->default_values($row); is( $form->get_field('id')->default, 2 ); is( $form->get_field('type_id')->default, 3 ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/has_one_nested.yml0000644000175100017520000000036213262760616022543 0ustar carlcarl--- auto_fieldset: nested_name: foo elements: - type: Hidden name: id - type: Text name: text_col - type: Block nested_name: user elements: - type: Text name: name - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/opt_accessor.t0000644000175100017520000000142213262760616021711 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/opt_accessor.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler row $master->create_related( 'user', { name => 'foo', } ); # row we're going to use $master->create_related( 'user', { title => 'mr', name => 'billy bob', } ); { my $row = $schema->resultset('User')->find(2); $form->model->default_values($row); my $fs = $form->get_element; is( $fs->get_field('id')->render_data->{value}, 2 ); is( $fs->get_field('fullname')->render_data->{value}, 'mr billy bob' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/methods.yml0000644000175100017520000000015013262760616021223 0ustar carlcarl--- elements: - type: Text name: method_test - type: Select name: method_select_testHTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable.t0000644000175100017520000000255313262760616023216 0ustar carlcarluse strict; use warnings; use Test::More tests => 8; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/has_many_repeatable.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler $master->create_related( 'user', { name => 'filler', addresses => [ { address => 'somewhere', } ] } ); $master->create_related( 'user', { name => 'filler2', } ); $master->create_related( 'user', { name => 'filler3', } ); # row we're going to use $master->create_related( 'user', { name => 'nick', addresses => [ { address => 'home', }, { address => 'office', } ] } ); { my $row = $schema->resultset('User')->find(4); $form->model->default_values($row); is( $form->get_field('id')->default, '4' ); is( $form->get_field('name')->default, 'nick' ); is( $form->get_field('count')->default, '2' ); my $block = $form->get_all_element( { nested_name => 'addresses' } ); my @reps = @{ $block->get_elements }; is( scalar @reps, 2 ); is( $reps[0]->get_field('id')->default, '2' ); is( $reps[0]->get_field('address')->default, 'home' ); is( $reps[1]->get_field('id')->default, '3' ); is( $reps[1]->get_field('address')->default, 'office' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_select.t0000644000175100017520000000177513262760616022376 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/has_many_select.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); { # insert some entries we'll ignore, so our rels don't have same ids # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # address 1 $u1->create_related( 'addresses' => { address => 'somewhere' } ); # should get user id 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); # should get address id 2 $u2->create_related( 'addresses', { address => 'home' } ); # should get address id 3 $u2->create_related( 'addresses', { address => 'office' } ); } { my $row = $schema->resultset('User')->find(2); $form->model->default_values($row); is_deeply( $form->get_field('addresses')->default, [ 2, 3 ] ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/opt_accessor_nested.yml0000644000175100017520000000030213262760616023605 0ustar carlcarl--- auto_fieldset: nested_name: foo elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/opt_accessor.yml0000644000175100017520000000025713262760616022254 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/basic_nested.yml0000644000175100017520000000113213262760616022204 0ustar carlcarl--- auto_fieldset: nested_name: foo 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 HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable_nested.yml0000644000175100017520000000052613262760616026007 0ustar carlcarl--- auto_fieldset: nested_name: foo elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: bands counter_name: count elements: - type: Hidden name: id - type: Text name: band - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable_new.yml0000644000175100017520000000055113262760616025314 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: bands counter_name: count model_config: empty_rows: 1 elements: - type: Hidden name: id - type: Text name: band - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_select_nested.t0000644000175100017520000000211513262760616024620 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/many_to_many_select_nested.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler { $master->create_related( 'user', { name => 'John', } ); $master->create_related( 'user', { name => 'Ringo', } ); my $user3 = $master->create_related( 'user', { name => 'George', } ); $user3->add_to_bands( { band => 'the kinks', } ); } # row we're going to use { my $paul = $master->create_related( 'user', { name => 'Paul', } ); $paul->add_to_bands( { band => 'the beatles', } ); $paul->add_to_bands( { band => 'wings', } ); } { my $row = $schema->resultset('User')->find(4); $form->model->default_values( $row, { nested_base => 'foo' } ); is( $form->get_field('id')->default, 4 ); is( $form->get_field('name')->default, 'Paul' ); is_deeply( $form->get_field('bands')->default, [ 2, 3 ] ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_select_nested.yml0000644000175100017520000000030513262760616025155 0ustar carlcarl--- auto_fieldset: nested_name: foo elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_select.yml0000644000175100017520000000031013262760616022714 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: addresses - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable.yml0000644000175100017520000000051213262760616023545 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count elements: - type: Hidden name: id - type: Text name: address - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable_new.t0000644000175100017520000000330413262760616024755 0ustar carlcarluse strict; use warnings; use Test::More tests => 12; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file( 't/default_values/many_to_many_repeatable_new.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler { my $user = $master->create_related( 'user', { name => 'filler', } ); $user->add_to_bands( { band => 'a', } ); $master->create_related( 'user', { name => 'filler2', } ); $master->create_related( 'user', { name => 'filler3', } ); $master->create_related( 'user', { name => 'filler4', } ); } # row we're going to use { my $user = $master->create_related( 'user', { name => 'nick', } ); $user->add_to_bands( { band => 'b', } ); $user->add_to_bands( { band => 'c', } ); $user->add_to_bands( { band => 'd', } ); } { my $row = $schema->resultset('User')->find(5); $form->model->default_values($row); is( $form->get_field('id')->default, '5' ); is( $form->get_field('name')->default, 'nick' ); is( $form->get_field('count')->default, '4' ); my $block = $form->get_all_element( { nested_name => 'bands' } ); my @reps = @{ $block->get_elements }; is( scalar @reps, 4 ); is( $reps[0]->get_field('id')->default, '2' ); is( $reps[0]->get_field('band')->default, 'b' ); is( $reps[1]->get_field('id')->default, '3' ); is( $reps[1]->get_field('band')->default, 'c' ); is( $reps[2]->get_field('id')->default, '4' ); is( $reps[2]->get_field('band')->default, 'd' ); is( $reps[3]->get_field('id')->default, undef ); is( $reps[3]->get_field('band')->default, undef ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/multi_label.t0000644000175100017520000000145413262760616021523 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/multi_label.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler row $master->create_related( 'user', { name => 'foo', } ); # row we're going to use $master->create_related( 'user', { title => 'mr', name => 'billy bob', } ); { my $row = $schema->resultset('User')->find(2); $form->model->default_values($row); my $multi = $form->get_element({ type => 'Multi' }); is( $multi->render_data->{label}, 'mr' ); my $name = $multi->get_field('name')->render_data; is( $name->{value}, 'billy bob' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/opt_accessor_nested.t0000644000175100017520000000154413262760616023260 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/opt_accessor_nested.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler row $master->create_related( 'user', { name => 'foo', } ); # row we're going to use $master->create_related( 'user', { title => 'mr', name => 'billy bob', } ); { my $row = $schema->resultset('User')->find(2); $form->model->default_values( $row, { nested_base => 'foo' } ); is( $form->get_field( { nested_name => 'foo.id' } )->render_data->{value}, 2 ); is( $form->get_field( { nested_name => 'foo.fullname' } ) ->render_data->{value}, 'mr billy bob' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_delete_true.t0000644000175100017520000000343513262760616025577 0ustar carlcarluse strict; use warnings; use Test::More tests => 18; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/has_many_repeatable_delete_true.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # row we're going to use $master->create_related( 'user', { name => 'nick', addresses => [ { address => 'home', }, { address => 'office', } ] } ); { my $row = $schema->resultset('User')->find(1); $form->model->default_values($row); is( $form->get_field('id')->default, '1' ); is( $form->get_field('name')->default, 'nick' ); is( $form->get_field('count')->default, '4' ); my $block = $form->get_all_element( { nested_name => 'addresses' } ); my @reps = @{ $block->get_elements }; is( scalar @reps, 4 ); is( $reps[0]->nested_name, 'addresses_1' ); is( $reps[0]->get_field('id')->default, '1' ); is( $reps[0]->get_field('address')->default, 'home' ); ok( $reps[0]->get_field({ type => 'Checkbox' }) ); is( $reps[1]->nested_name, 'addresses_2' ); is( $reps[1]->get_field('id')->default, '2' ); is( $reps[1]->get_field('address')->default, 'office' ); ok( $reps[1]->get_field({ type => 'Checkbox' }) ); # empty rows is( $reps[2]->get_field('id')->default, undef ); is( $reps[2]->get_field('address')->default, undef ); # checkbox has been removed ok( !$reps[2]->get_field({ type => 'Checkbox' }) ); is( $reps[3]->get_field('id')->default, undef ); is( $reps[3]->get_field('address')->default, undef ); # checkbox has been removed ok( !$reps[3]->get_field({ type => 'Checkbox' }) ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_delete_true.yml0000644000175100017520000000071713262760616026135 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count model_config: empty_rows: 2 elements: - type: Hidden name: id - type: Text name: address - type: Checkbox name: delete model_config: delete_if_true: 1 - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_nested.t0000644000175100017520000000367613262760616024567 0ustar carlcarluse strict; use warnings; use Test::More tests => 12; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/has_many_repeatable_nested.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler $master->create_related( 'user', { name => 'filler', addresses => [ { address => 'somewhere', } ] } ); $master->create_related( 'user', { name => 'filler2', } ); $master->create_related( 'user', { name => 'filler3', } ); # row we're going to use $master->create_related( 'user', { name => 'nick', addresses => [ { address => 'home', }, { address => 'office', } ] } ); { my $row = $schema->resultset('User')->find(4); $form->model->default_values( $row, { nested_base => 'foo' } ); is( $form->get_field( { nested_name => 'foo.id' } )->default, '4' ); is( $form->get_field( { nested_name => 'foo.name' } )->default, 'nick' ); is( $form->get_field( { nested_name => 'foo.count' } )->default, '2' ); my $block = $form->get_all_element( { nested_name => 'addresses' } ); my @reps = @{ $block->get_elements }; is( scalar @reps, 2 ); is( $reps[0]->get_field('id')->default, '2' ); is( $reps[0]->get_field('address')->default, 'home' ); is( $reps[1]->get_field('id')->default, '3' ); is( $reps[1]->get_field('address')->default, 'office' ); # check the same values from the form, not the block is( $form->get_field( { nested_name => 'foo.addresses_1.id' } )->default, '2' ); is( $form->get_field( { nested_name => 'foo.addresses_1.address' } ) ->default, 'home' ); is( $form->get_field( { nested_name => 'foo.addresses_2.id' } )->default, '3' ); is( $form->get_field( { nested_name => 'foo.addresses_2.address' } ) ->default, 'office' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/might_have.t0000644000175100017520000000244513262760616021346 0ustar carlcarluse 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/default_values/might_have.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); my $note_rs = $schema->resultset('Note'); { # insert some entries we'll ignore, so our rels don't have same ids # test id 1 my $t1 = $rs->new_result( { text_col => 'xxx' } ); $t1->insert; # test id 2 my $t2 = $rs->new_result( { text_col => 'yyy' } ); $t2->insert; # note id 1 my $n1 = $t2->new_related( 'note', { note => 'zzz' } ); $n1->insert; # should get test id 3 my $master = $rs->new_result( { text_col => 'a', } ); $master->insert; # should get note id 2 my $note = $master->new_related( 'note', { note => 'abc' } ); $note->insert; } { my $row = $rs->find(3); $form->model->default_values($row); is( $form->get_field('id')->render_data->{value}, 3 ); is( $form->get_field('text_col')->render_data->{value}, 'a' ); my $block = $form->get_all_element( { nested_name => 'note' } ); is( $block->get_field('id')->render_data->{value}, 2 ); is( $block->get_field('note')->render_data->{value}, 'abc' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/has_one.t0000644000175100017520000000226513262760616020647 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/has_one.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); { # insert some entries we'll ignore, so our rels don't have same ids # test id 1 my $t1 = $rs->new_result( { text_col => 'xxx' } ); $t1->insert; # test id 2 my $t2 = $rs->new_result( { text_col => 'yyy' } ); $t2->insert; # user id 1 my $n1 = $t2->new_related( 'user', { name => 'foo' } ); $n1->insert; # should get test id 3 my $master = $rs->new_result( { text_col => 'a', } ); $master->insert; # should get note id 2 my $user = $master->new_related( 'user', { name => 'bar' } ); $user->insert; } { my $row = $rs->find(3); $form->model->default_values($row); is( $form->get_field('id')->render_data->{value}, 3 ); is( $form->get_field('text_col')->render_data->{value}, 'a' ); my $block = $form->get_all_element( { nested_name => 'user' } ); is( $block->get_field('name')->render_data->{value}, 'bar' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/belongs_to_lookup_table.yml0000644000175100017520000000031513262760616024456 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Select name: type_id - type: Select name: type2_id - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable.yml0000644000175100017520000000050313262760616024440 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: bands counter_name: count elements: - type: Hidden name: id - type: Text name: band - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/empty_rows_zero.yml0000644000175100017520000000052113262760616023031 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Repeatable nested_name: addresses counter_name: count model_config: empty_rows: 0 elements: - type: Hidden name: id - type: Text name: address - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_select.yml0000644000175100017520000000026213262760616023615 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many-has_many.yml0000644000175100017520000000076513262760616024063 0ustar carlcarl--- auto_fieldset: 1 elements: - name: band - type: Hidden name: count - type: Repeatable nested_name: users counter_name: count elements: - type: Hidden name: id - type: Text name: name - type: Hidden name: count - type: Repeatable nested_name: addresses counter_name: count elements: - type: Hidden name: id - name: address - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_new.t0000644000175100017520000000313113262760616024060 0ustar carlcarluse strict; use warnings; use Test::More tests => 12; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/has_many_repeatable_new.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler $master->create_related( 'user', { name => 'filler', addresses => [ { address => 'somewhere', } ] } ); $master->create_related( 'user', { name => 'filler2', } ); $master->create_related( 'user', { name => 'filler3', } ); # row we're going to use $master->create_related( 'user', { name => 'nick', addresses => [ { address => 'home', }, { address => 'office', } ] } ); { my $row = $schema->resultset('User')->find(4); $form->model->default_values($row); is( $form->get_field('id')->default, '4' ); is( $form->get_field('name')->default, 'nick' ); is( $form->get_field('count')->default, '4' ); my $block = $form->get_all_element( { nested_name => 'addresses' } ); my @reps = @{ $block->get_elements }; is( scalar @reps, 4 ); is( $reps[0]->get_field('id')->default, '2' ); is( $reps[0]->get_field('address')->default, 'home' ); is( $reps[1]->get_field('id')->default, '3' ); is( $reps[1]->get_field('address')->default, 'office' ); is( $reps[2]->get_field('id')->default, undef ); is( $reps[2]->get_field('address')->default, undef ); is( $reps[3]->get_field('id')->default, undef ); is( $reps[3]->get_field('address')->default, undef ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_checkboxgroup.yml0000644000175100017520000000025113262760616025177 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Checkboxgroup name: bands - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/might_have.yml0000644000175100017520000000041213262760616021674 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Block nested_name: note elements: - type: Hidden name: id - type: Textarea name: note - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable.t0000644000175100017520000000312013262760616024100 0ustar carlcarluse strict; use warnings; use Test::More tests => 10; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/many_to_many_repeatable.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler { my $user = $master->create_related( 'user', { name => 'filler', } ); $user->add_to_bands( { band => 'a', } ); $master->create_related( 'user', { name => 'filler2', } ); $master->create_related( 'user', { name => 'filler3', } ); $master->create_related( 'user', { name => 'filler4', } ); } # row we're going to use { my $user = $master->create_related( 'user', { name => 'nick', } ); $user->add_to_bands( { band => 'b', } ); $user->add_to_bands( { band => 'c', } ); $user->add_to_bands( { band => 'd', } ); } { my $row = $schema->resultset('User')->find(5); $form->model->default_values($row); is( $form->get_field('id')->default, '5' ); is( $form->get_field('name')->default, 'nick' ); is( $form->get_field('count')->default, '3' ); my $block = $form->get_all_element( { nested_name => 'bands' } ); my @reps = @{ $block->get_elements }; is( scalar @reps, 3 ); is( $reps[0]->get_field('id')->default, '2' ); is( $reps[0]->get_field('band')->default, 'b' ); is( $reps[1]->get_field('id')->default, '3' ); is( $reps[1]->get_field('band')->default, 'c' ); is( $reps[2]->get_field('id')->default, '4' ); is( $reps[2]->get_field('band')->default, 'd' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/empty_rows_zero.t0000644000175100017520000000177313262760616022505 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/empty_rows_zero.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler $master->create_related( 'user', { name => 'filler', addresses => [ { address => 'somewhere', } ] } ); $master->create_related( 'user', { name => 'filler2', } ); $master->create_related( 'user', { name => 'filler3', } ); # row we're going to use $master->create_related( 'user', { name => 'nick' } ); { my $row = $schema->resultset('User')->find(4); $form->model->default_values($row); is( $form->get_field('id')->default, '4' ); is( $form->get_field('count')->default, '0' ); my $block = $form->get_all_element( { nested_name => 'addresses' } ); my @reps = @{ $block->get_elements }; is( scalar @reps, 0 ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_checkboxgroup.t0000644000175100017520000000206113262760616024642 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/many_to_many_checkboxgroup.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler { $master->create_related( 'user', { name => 'John', } ); $master->create_related( 'user', { name => 'Ringo', } ); my $user3 = $master->create_related( 'user', { name => 'George', } ); $user3->add_to_bands( { band => 'the kinks', } ); } # row we're going to use { my $paul = $master->create_related( 'user', { name => 'Paul', } ); $paul->add_to_bands( { band => 'the beatles', } ); $paul->add_to_bands( { band => 'wings', } ); } { my $row = $schema->resultset('User')->find(4); $form->model->default_values($row); is( $form->get_field('id')->default, 4 ); is( $form->get_field('name')->default, 'Paul' ); is_deeply( $form->get_field('bands')->default, [ 2, 3 ] ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_combobox.yml0000644000175100017520000000031213262760616023247 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: ComboBox name: addresses - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable_nested.t0000644000175100017520000000440413262760616025450 0ustar carlcarluse strict; use warnings; use Test::More tests => 16; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file( 't/default_values/many_to_many_repeatable_nested.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler { my $user = $master->create_related( 'user', { name => 'filler', } ); $user->add_to_bands( { band => 'a', } ); $master->create_related( 'user', { name => 'filler2', } ); $master->create_related( 'user', { name => 'filler3', } ); $master->create_related( 'user', { name => 'filler4', } ); } # row we're going to use { my $user = $master->create_related( 'user', { name => 'nick', } ); $user->add_to_bands( { band => 'b', } ); $user->add_to_bands( { band => 'c', } ); $user->add_to_bands( { band => 'd', } ); } { my $row = $schema->resultset('User')->find(5); $form->model->default_values( $row, { nested_base => 'foo' } ); is( $form->get_field( { nested_name => 'foo.id' } )->default, '5' ); is( $form->get_field( { nested_name => 'foo.name' } )->default, 'nick' ); is( $form->get_field( { nested_name => 'foo.count' } )->default, '3' ); my $block = $form->get_all_element( { nested_name => 'bands' } ); my @reps = @{ $block->get_elements }; is( scalar @reps, 3 ); is( $reps[0]->get_field('id')->default, '2' ); is( $reps[0]->get_field('band')->default, 'b' ); is( $reps[1]->get_field('id')->default, '3' ); is( $reps[1]->get_field('band')->default, 'c' ); is( $reps[2]->get_field('id')->default, '4' ); is( $reps[2]->get_field('band')->default, 'd' ); # check the same values from the form, not the block is( $form->get_field( { nested_name => 'foo.bands_1.id' } )->default, '2' ); is( $form->get_field( { nested_name => 'foo.bands_1.band' } )->default, 'b' ); is( $form->get_field( { nested_name => 'foo.bands_2.id' } )->default, '3' ); is( $form->get_field( { nested_name => 'foo.bands_2.band' } )->default, 'c' ); is( $form->get_field( { nested_name => 'foo.bands_3.id' } )->default, '4' ); is( $form->get_field( { nested_name => 'foo.bands_3.band' } )->default, 'd' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/basic.yml0000644000175100017520000000125513262760616020650 0ustar carlcarl--- 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: 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: Date name: date_col - type: Text name: unknown_col - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/nested_name_accessor.t0000644000175100017520000000152613262760616023376 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/nested_name_accessor.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler row $master->create_related( 'user', { name => 'filler', } ); # row we're going to use my $row = $master->create_related( 'user', { name => 'mr. foo', } ); $row->create_related( 'hasmanys', { key => 'bar', value => 'a' } ); $row->create_related( 'hasmanys', { key => 'foo', value => 'b' } ); { my $row = $schema->resultset('User')->find(2); $form->model->default_values($row); is( $form->get_field('name')->default, 'mr. foo' ); is ( $form->get_field('value')->default, 'b' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/methods.t0000644000175100017520000000103013262760616020663 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/methods.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); # filler row $rs->create( { text_col => 'filler', } ); { my $row = $rs->find(1); $form->model->default_values($row); my $field = $form->get_element('method_test'); is( $field->render_data->{value}, "filler" ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_nested.yml0000644000175100017520000000053513262760616025114 0ustar carlcarl--- auto_fieldset: nested_name: foo elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count elements: - type: Hidden name: id - type: Text name: address - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/belongs_to_lookup_table_combobox.yml0000644000175100017520000000063013262760616026346 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: ComboBox name: type # set this, so options_from_model() populates the menu, # so we can test the correct default is set model_config: resultset: Type select_column: id text_column: type - type: ComboBox name: type2_id - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_select.t0000644000175100017520000000205213262760616023256 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/many_to_many_select.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler { $master->create_related( 'user', { name => 'John', } ); $master->create_related( 'user', { name => 'Ringo', } ); my $user3 = $master->create_related( 'user', { name => 'George', } ); $user3->add_to_bands( { band => 'the kinks', } ); } # row we're going to use { my $paul = $master->create_related( 'user', { name => 'Paul', } ); $paul->add_to_bands( { band => 'the beatles', } ); $paul->add_to_bands( { band => 'wings', } ); } { my $row = $schema->resultset('User')->find(4); $form->model->default_values($row); is( $form->get_field('id')->default, 4 ); is( $form->get_field('name')->default, 'Paul' ); is_deeply( $form->get_field('bands')->default, [ 2, 3 ] ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many-has_many.t0000644000175100017520000000635613262760616023527 0ustar carlcarluse strict; use warnings; use Test::More tests => 22; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/many_to_many-has_many.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $user = $master->create_related( 'user', { name => 'filler', } ); # band 1 $user->add_to_bands( { band => 'a', } ); # address 1 $user->add_to_addresses( { address => 'b' } ); # user 2,3,4 $master->create_related( 'user', { name => 'filler2', } ); $master->create_related( 'user', { name => 'filler3', } ); $master->create_related( 'user', { name => 'filler4', } ); } # rows we're going to use { # band 2 my $band = $schema->resultset('Band')->create({ band => 'band 2' }); # user 5,6 my $user1 = $band->add_to_users({ name => 'user 5', master => $master->id }); my $user2 = $band->add_to_users({ name => 'user 6', master => $master->id }); # address 2,3 $user1->create_related( 'addresses', { address => 'add 2' } ); $user1->create_related( 'addresses', { address => 'add 3' } ); # address 4 $user2->create_related( 'addresses', { address => 'add 4' } ); } { my $row = $schema->resultset('Band')->find(2); $form->model->default_values($row); is( $form->get_field('band')->default, 'band 2' ); is( $form->get_field('count')->default, '2' ); my $user_repeatable = $form->get_all_element( { nested_name => 'users' } ); my @users = @{ $user_repeatable->get_elements }; is( scalar @users, 2 ); # user 5 { is( $users[0]->nested_name, 'users_1' ); is( $users[0]->get_field('id')->default, '5' ); is( $users[0]->get_field('name')->default, 'user 5' ); is( $users[0]->get_field('count')->default, '2' ); my $addresses_repeatable = $users[0]->get_all_element({ nested_name => 'addresses' }); my @addresses = @{ $addresses_repeatable->get_elements }; is( scalar @addresses, 2 ); # address 2 is( $addresses[0]->nested_name, 'addresses_1' ); is( $addresses[0]->get_field('id')->default, '2' ); is( $addresses[0]->get_field('address')->default, 'add 2' ); # address 3 is( $addresses[1]->nested_name, 'addresses_2' ); is( $addresses[1]->get_field('id')->default, '3' ); is( $addresses[1]->get_field('address')->default, 'add 3' ); } # user 6 { is( $users[1]->nested_name, 'users_2' ); is( $users[1]->get_field('id')->default, '6' ); is( $users[1]->get_field('name')->default, 'user 6' ); is( $users[1]->get_field('count')->default, '1' ); my $addresses_repeatable = $users[1]->get_all_element({ nested_name => 'addresses' }); my @addresses = @{ $addresses_repeatable->get_elements }; is( scalar @addresses, 1 ); # address 4 is( $addresses[0]->nested_name, 'addresses_1' ); is( $addresses[0]->get_field('id')->default, '4' ); is( $addresses[0]->get_field('address')->default, 'add 4' ); } } HTML-FormFu-Model-DBIC-2.03/t/default_values/basic_nested.t0000644000175100017520000000535013262760616021654 0ustar carlcarluse strict; use warnings; use Test::More tests => 25; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/basic_nested.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); # filler row $rs->create( { text_col => 'filler', } ); # row we're going to use $rs->create( { text_col => 'a', password_col => 'b', checkbox_col => 'foo', select_col => '2', radio_col => 'yes', radiogroup_col => '3', date_col => '2006-12-31 00:00:00' } ); { my $row = $rs->find(2); $form->model->default_values( $row, { nested_base => 'foo' } ); my $fs = $form->get_element; is( $fs->get_field( { nested_name => 'foo.id' } )->render_data->{value}, 2 ); is( $fs->get_field( { nested_name => 'foo.text_col' } ) ->render_data->{value}, 'a' ); is( $fs->get_field( { nested_name => 'foo.password_col' } ) ->render_data->{value}, undef ); my $checkbox = $fs->get_field( { nested_name => 'foo.checkbox_col' } )->render_data; is( $checkbox->{value}, 'foo' ); is( $checkbox->{attributes}{checked}, 'checked' ); # accessing undocumented HTML::FormFu internals below # may break in the future my $select = $fs->get_field( { nested_name => 'foo.select_col' } )->render_data; is( $select->{options}[0]{value}, 1 ); ok( !exists $select->{options}[0]{attributes}{selected} ); is( $select->{options}[1]{value}, 2 ); is( $select->{options}[1]{attributes}{selected}, 'selected' ); is( $select->{options}[2]{value}, 3 ); ok( !exists $select->{options}[2]{attributes}{selected} ); my @radio = map { $_->render_data } @{ $form->get_fields( { nested_name => 'foo.radio_col' } ) }; is( $radio[0]->{value}, 'yes' ); is( $radio[0]->{attributes}{checked}, 'checked' ); is( $radio[1]->{value}, 'no' ); ok( !exists $radio[1]->{attributes}{checked} ); my @rg_option = @{ $fs->get_field( { nested_name => 'foo.radiogroup_col' } ) ->render_data->{options} }; is( $rg_option[0]->{value}, 1 ); ok( !exists $rg_option[0]->{attributes}{checked} ); is( $rg_option[1]->{value}, 2 ); ok( !exists $rg_option[1]->{attributes}{checked} ); is( $rg_option[2]->{value}, 3 ); is( $rg_option[2]->{attributes}{checked}, 'checked' ); # column is inflated my $date = $fs->get_field( { nested_name => 'foo.date_col' } )->default; isa_ok( $date, 'DateTime' ); is( $date->day, '31' ); is( $date->month, '12' ); is( $date->year, '2006' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_combobox.t0000644000175100017520000000177613262760616022730 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/has_many_combobox.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); { # insert some entries we'll ignore, so our rels don't have same ids # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # address 1 $u1->create_related( 'addresses' => { address => 'somewhere' } ); # should get user id 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); # should get address id 2 $u2->create_related( 'addresses', { address => 'home' } ); # should get address id 3 $u2->create_related( 'addresses', { address => 'office' } ); } { my $row = $schema->resultset('User')->find(2); $form->model->default_values($row); is_deeply( $form->get_field('addresses')->default, [ 2, 3 ] ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/multi_label.yml0000644000175100017520000000031413262760616022053 0ustar carlcarl--- elements: - type: Multi model_config: label: title elements: - type: Hidden name: id - type: Text name: name - type : Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_new.yml0000644000175100017520000000056013262760616024421 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count model_config: empty_rows: 2 elements: - type: Hidden name: id - type: Text name: address - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/label.t0000644000175100017520000000137413262760616020312 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/label.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler row $master->create_related( 'user', { name => 'foo', } ); # row we're going to use $master->create_related( 'user', { title => 'mr', name => 'billy bob', } ); { my $row = $schema->resultset('User')->find(2); $form->model->default_values($row); my $fs = $form->get_element; my $name = $fs->get_field('name')->render_data; is( $name->{value}, 'billy bob' ); is( $name->{label}, 'mr' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/belongs_to_lookup_table_combobox.t0000644000175100017520000000210213262760616026004 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/belongs_to_lookup_table_combobox.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $rs = $schema->resultset('Master'); { my $type_rs = $schema->resultset('Type'); # types $type_rs->delete; $type_rs->create( { type => 'type 1' } ); $type_rs->create( { type => 'type 2' } ); $type_rs->create( { type => 'type 3' } ); } # filler row $rs->create( { text_col => 'filler', } ); # row we're going to use $rs->create( { text_col => 'a', type_id => 3, } ); { my $row = $rs->find(2); $form->process; $form->model->default_values($row); is( $form->get_field('id')->default, 2 ); my $type_field = $form->get_field('type'); is( $type_field->default, 3 ); # test correct select option is selected like( "$type_field", qr{} ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/label.yml0000644000175100017520000000024513262760616020644 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name model_config: label: title - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/default_values/has_one_nested.t0000644000175100017520000000253413262760616022210 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/has_one_nested.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); { # insert some entries we'll ignore, so our rels don't have same ids # test id 1 my $t1 = $rs->new_result( { text_col => 'xxx' } ); $t1->insert; # test id 2 my $t2 = $rs->new_result( { text_col => 'yyy' } ); $t2->insert; # user id 1 my $n1 = $t2->new_related( 'user', { name => 'foo' } ); $n1->insert; # should get test id 3 my $master = $rs->new_result( { text_col => 'a', } ); $master->insert; # should get note id 2 my $user = $master->new_related( 'user', { name => 'bar' } ); $user->insert; } { my $row = $rs->find(3); $form->model->default_values( $row, { nested_base => 'foo' } ); is( $form->get_field( { nested_name => 'foo.id' } )->render_data->{value}, 3 ); is( $form->get_field( { nested_name => 'foo.text_col' } ) ->render_data->{value}, 'a' ); my $block = $form->get_all_element( { nested_name => 'user' } ); is( $block->get_field( { nested_name => 'foo.user.name' } ) ->render_data->{value}, 'bar' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/basic.t0000644000175100017520000000600413262760616020307 0ustar carlcarluse strict; use warnings; use Test::More tests => 31; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/basic.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); # filler row $rs->create( { text_col => 'filler', } ); # row we're going to use $rs->create( { text_col => 'a', password_col => 'b', checkbox_col => 'foo', select_col => '2', radio_col => 'yes', radiogroup_col => '3', array_col => [qw(one two)], date_col => '2006-12-31 00:00:00' } ); { my $row = $rs->find(2); $form->model->default_values($row); my $fs = $form->get_element; is( $fs->get_field('id')->render_data->{value}, 2 ); is( $fs->get_field('text_col')->render_data->{value}, 'a' ); is( $fs->get_field('password_col')->render_data->{value}, undef ); my $checkbox = $fs->get_field('checkbox_col')->render_data; is( $checkbox->{value}, 'foo' ); is( $checkbox->{attributes}{checked}, 'checked' ); # accessing undocumented HTML::FormFu internals below # may break in the future my $select = $fs->get_field('select_col')->render_data; is( $select->{options}[0]{value}, 1 ); ok( !exists $select->{options}[0]{attributes}{selected} ); is( $select->{options}[1]{value}, 2 ); is( $select->{options}[1]{attributes}{selected}, 'selected' ); is( $select->{options}[2]{value}, 3 ); ok( !exists $select->{options}[2]{attributes}{selected} ); my @radio = map { $_->render_data } @{ $form->get_fields('radio_col') }; is( $radio[0]->{value}, 'yes' ); is( $radio[0]->{attributes}{checked}, 'checked' ); is( $radio[1]->{value}, 'no' ); ok( !exists $radio[1]->{attributes}{checked} ); my @rg_option = @{ $fs->get_field('radiogroup_col')->render_data->{options} }; is( $rg_option[0]->{value}, 1 ); ok( !exists $rg_option[0]->{attributes}{checked} ); is( $rg_option[1]->{value}, 2 ); ok( !exists $rg_option[1]->{attributes}{checked} ); is( $rg_option[2]->{value}, 3 ); is( $rg_option[2]->{attributes}{checked}, 'checked' ); # column is inflated # my $ary_col = $fs->get_field('array_col')->default; # isa_ok( $ary_col, 'ARRAY' ); my $ary_col = $fs->get_field('array_col')->render_data; is( $ary_col->{options}[0]{value}, 'one' ); is( $ary_col->{options}[0]{attributes}{checked}, 'checked' ); is( $ary_col->{options}[1]{value}, 'two' ); is( $ary_col->{options}[1]{attributes}{checked}, 'checked' ); is( $ary_col->{options}[2]{value}, 'three' ); ok( !exists $ary_col->{options}[2]{attributes}{checked} ); # column is inflated my $date = $fs->get_field('date_col')->default; isa_ok( $date, 'DateTime' ); is( $date->day, '31' ); is( $date->month, '12' ); is( $date->year, '2006' ); } HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_label.t0000644000175100017520000000307713262760616024357 0ustar carlcarluse strict; use warnings; use Test::More tests => 10; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/has_many_repeatable_label.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler $master->create_related( 'user', { name => 'filler', addresses => [ { address => 'somewhere', } ] } ); $master->create_related( 'user', { name => 'filler2', } ); $master->create_related( 'user', { name => 'filler3', } ); # row we're going to use $master->create_related( 'user', { name => 'nick', addresses => [ { address => 'home', my_label => 'label 1' }, { address => 'office', my_label => 'label 2' }, ] } ); { my $row = $schema->resultset('User')->find(4); $form->model->default_values($row); is( $form->get_field('id')->default, '4' ); is( $form->get_field('name')->default, 'nick' ); is( $form->get_field('count')->default, '2' ); my $block = $form->get_all_element( { nested_name => 'addresses' } ); my @reps = @{ $block->get_elements }; is( scalar @reps, 2 ); is( $reps[0]->get_field('id')->default, '2' ); is( $reps[0]->get_field('address')->default, 'home' ); is( $reps[0]->get_field('address')->label, 'label 1' ); is( $reps[1]->get_field('id')->default, '3' ); is( $reps[1]->get_field('address')->default, 'office' ); is( $reps[1]->get_field('address')->label, 'label 2' ); } HTML-FormFu-Model-DBIC-2.03/t/update/0000775000175100017520000000000013262760616015322 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_many_new_exceed_max.t0000644000175100017520000000224413262760616025551 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; use lib qw(t/lib lib); use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_many_repeatable_many_new.yml'); my $schema = new_schema(); my $user_rs = $schema->resultset('User'); my $address_rs = $schema->resultset('Address'); { $form->process( { 'id' => '', 'name' => 'new nick', 'master' => 1, 'count' => 2, 'addresses_1.id' => '', 'addresses_1.address' => 'new home', 'addresses_2.id' => '', 'addresses_2.address' => 'new office', 'addresses_3.id' => '', 'addresses_3.address' => 'new office2', } ); ok( $form->submitted_and_valid ); my $row = $user_rs->new( {} ); $form->model('DBIC')->update($row); my $user = $user_rs->find(1); is( $user->name, 'new nick' ); my @add = $user->addresses->all; # 3rd address isn't inserted is( scalar @add, 2 ); is( $add[0]->id, 1 ); is( $add[0]->address, 'new home' ); is( $add[1]->id, 2 ); is( $add[1]->address, 'new office' ); } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup_read_only.yml0000644000175100017520000000035213262760616025514 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Checkboxgroup name: bands model_config: read_only: 1 options_from_model: 0 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_implicit.yml0000644000175100017520000000056113262760616024573 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count model_config: empty_rows: 1 elements: - type: Hidden name: id - type: Text name: address - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/ignore_if_empty.yml0000644000175100017520000000017413262760616021224 0ustar carlcarl--- model_config: resultset: User elements: - type: Password name: name model_config: ignore_if_empty: 1 HTML-FormFu-Model-DBIC-2.03/t/update/ignore_if_empty.t0000644000175100017520000000146713262760616020674 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/ignore_if_empty.yml'); my $schema = new_schema(); my $rs = $schema->resultset('User')->create( { master => 1, name => "foo", title => 'bar' } ); is( $rs->name, "foo" ); { $form->process( { name => 'test' } ); $form->model->update($rs); is( $rs->name, "test" ); } { $form->process( { name => undef } ); $form->model->update($rs); is( $rs->name, "test" ); } { $form->process( { name => 0 } ); $form->model->update($rs); is( $rs->name, "0" ); } { $form->process( { name => " " } ); $form->model->update($rs); is( $rs->name, " " ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_one.yml0000644000175100017520000000040613262760616017457 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Block nested_name: user elements: - type: Hidden name: id - type: Text name: name - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/has_one_no_id.yml0000644000175100017520000000033713262760616020632 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Block nested_name: user elements: - type: Text name: name - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/opt_accessor.t0000644000175100017520000000161313262760616020172 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/opt_accessor.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'mr. bar', } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'mr. foo', } ); } { $form->process( { id => 2, fullname => 'mr billy bob', } ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $row = $schema->resultset('User')->find(2); is( $row->title, 'mr' ); is( $row->name, 'billy bob' ); is( $row->fullname, 'mr billy bob' ); } HTML-FormFu-Model-DBIC-2.03/t/update/methods.yml0000644000175100017520000000023713262760616017510 0ustar carlcarl--- elements: - type: Text name: method_test - type: Select name: method_select_test - type: Checkbox name: method_checkbox_test HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable.t0000644000175100017520000000371313262760616021474 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_many_repeatable.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # address 1 $u1->create_related( 'addresses' => { address => 'somewhere' } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); # address 2 $u2->create_related( 'addresses', { address => 'home' } ); # address 3 $u2->create_related( 'addresses', { address => 'office' } ); } { $form->process( { 'id' => 2, 'name' => 'new nick', 'count' => 2, 'addresses_1.id' => 2, 'addresses_1.address' => 'new home', 'addresses_2.id' => 3, 'addresses_2.address' => 'new office', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $user = $schema->resultset('User')->find(2); is( $user->name, 'new nick' ); my @add = $user->addresses->all; is( scalar @add, 2 ); is( $add[0]->id, 2 ); is( $add[0]->address, 'new home' ); is( $add[1]->id, 3 ); is( $add[1]->address, 'new office' ); } my $el = $form->get_all_element({name => "name"}); $el->model_config->{read_only} = 1; { $form->process( { 'id' => 2, 'name' => 'new new nick', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $user = $schema->resultset('User')->find(2); is( $user->name, 'new nick' ); } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup_restricted.yml0000644000175100017520000000036213262760616025711 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Checkboxgroup name: bands model_config: model: Bands condition: manager: 1 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/basic_create.t0000644000175100017520000000301013262760616020103 0ustar carlcarluse strict; use warnings; use Test::More tests => 10; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/basic.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); # Fake submitted form $form->process( { id => 1, text_col => 'a', password_col => 'b', checkbox_col => 'foo', select_col => '2', combobox_col_select => 'sel', combobox_col_text => '', radio_col => 'yes', radiogroup_col => '3', array_col => [qw(one two)], } ); { my $row = $rs->new( {} ); $form->model->update($row); } { my $row = $rs->find(1); is( $row->text_col, 'a' ); is( $row->password_col, 'b' ); is( $row->checkbox_col, 'foo' ); is( $row->select_col, '2' ); is( $row->combobox_col, 'sel' ); is( $row->radio_col, 'yes' ); is( $row->radiogroup_col, '3' ); is( ($row->array_col)->[0], 'one' ); is( ($row->array_col)->[1], 'two' ); } $form->process( { id => '', text_col => 'a2', password_col => 'b2', checkbox_col => 'foo', select_col => '2', radio_col => 'yes', radiogroup_col => '3', } ); { my $row = $rs->new( {} ); $form->model->update($row); } { my $row = $rs->find(2); is( $row->text_col, 'a2' ); } HTML-FormFu-Model-DBIC-2.03/t/update/opt_accessor_nested.yml0000644000175100017520000000030013262760616022062 0ustar carlcarl--- auto_fieldset: nested_name: foo elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/opt_accessor.yml0000644000175100017520000000025713262760616020533 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/add_valid.t0000644000175100017520000000170413262760616017416 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/basic.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); # 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', } ); { $form->add_valid( 'not_in_form', 'xyz' ); my $row = $rs->new( {} ); $form->model->update($row); } { my $row = $rs->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' ); is( $row->not_in_form, 'xyz' ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_required_when.t0000644000175100017520000000355113262760616025266 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_many_repeatable_new_required_when.yml'); # a form is created with 'empty_rows' => 2 # but only 1 new row is filled in # test using a Required constraint # with 'when' pointing to the PK field my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # address 1 $u1->create_related( 'addresses' => { address => 'somewhere' } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); # address 2 $u2->create_related( 'addresses', { address => 'home' } ); # address 3 $u2->create_related( 'addresses', { address => 'office' } ); } { $form->process( { 'id' => 2, 'name' => 'new nick', 'count' => 4, 'addresses_1.id' => 2, 'addresses_1.address' => 'new home', 'addresses_2.id' => 3, 'addresses_2.address' => 'new office', 'addresses_3.id' => '', 'addresses_3.address' => 'new address', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $user = $schema->resultset('User')->find(2); is( $user->name, 'new nick' ); my @add = $user->addresses->all; is( scalar @add, 3 ); is( $add[0]->id, 2 ); is( $add[0]->address, 'new home' ); is( $add[1]->id, 3 ); is( $add[1]->address, 'new office' ); is( $add[2]->id, 4 ); is( $add[2]->address, 'new address' ); } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_repeatable_new.yml0000644000175100017520000000055513262760616023577 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: bands counter_name: count model_config: new_rows_max: 1 elements: - type: Hidden name: id - type: Text name: band - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_empty.t0000644000175100017520000000331113262760616023555 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_many_repeatable_new.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # address 1 $u1->create_related( 'addresses' => { address => 'somewhere' } ); } # rows we're going to use { # should get user id 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); $u2->insert; # should get address id 2 $u2->create_related( 'addresses', { address => 'home' } ); # should get address id 3 $u2->create_related( 'addresses', { address => 'office' } ); } { $form->process( { 'id' => 2, 'name' => 'new nick', 'count' => 3, 'addresses_1.id' => 2, 'addresses_1.address' => 'new home', 'addresses_2.id' => 3, 'addresses_2.address' => 'new office', 'addresses_3.id' => '', 'addresses_3.address' => '', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $user = $schema->resultset('User')->find(2); is( $user->name, 'new nick' ); my @add = $user->addresses->all; is( scalar @add, 2 ); # empty address not inserted is( $add[0]->id, 2 ); is( $add[0]->address, 'new home' ); is( $add[1]->id, 3 ); is( $add[1]->address, 'new office' ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable.yml0000644000175100017520000000051313262760616022025 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count elements: - type: Hidden name: id - type: Text name: address - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_repeatable_new.t0000644000175100017520000000274613262760616023245 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/many_to_many_repeatable_new.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')-> create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # band 1 $u1->add_to_bands({ band => 'a' }); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); # band 2,3 $u2->add_to_bands({ band => 'b' }); $u2->add_to_bands({ band => 'c' }); } { $form->process( { 'id' => 2, 'name' => 'new nick', 'count' => 3, 'bands_1.id' => 2, 'bands_1.band' => 'b++', 'bands_2.id' => 3, 'bands_2.band' => 'c++', 'bands_3.id' => '', 'bands_3.band' => 'd++' } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $user = $schema->resultset('User')->find(2); is( $user->name, 'new nick' ); my @add = $user->bands->all; is( scalar @add, 3 ); is( $add[0]->id, 2 ); is( $add[0]->band, 'b++' ); is( $add[1]->id, 3 ); is( $add[1]->band, 'c++' ); is( $add[2]->id, 4 ); is( $add[2]->band, 'd++' ); } HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to.t0000644000175100017520000000152613262760616017644 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/belongs_to_lookup_table.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); # Fake submitted form $form->process( { "id" => 3, "text_col" => 'a', 'type_id' => '1', 'type2_id' => '1', } ); # filler rows { # insert some entries we'll ignore, so our rels don't have same ids $rs->create( { id => 1 } ); $rs->create( { id => 2 } ); } { # master 3 my $master = $rs->create( { text_col => 'b', type_id => 2, type2_id => 2 } ); $form->model->update($master); } { my $row = $rs->find(3); is( $row->type->id, '1' ); is( $row->type2->id, '1' ); } HTML-FormFu-Model-DBIC-2.03/t/update/opt_accessor_nested.t0000644000175100017520000000167213262760616021541 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/opt_accessor_nested.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'mr. bar', } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'mr. foo', } ); } { $form->process( { 'foo.id' => 2, 'foo.fullname' => 'mr billy bob', } ); my $row = $schema->resultset('User')->find(2); $form->model->update( $row, { nested_base => 'foo' } ); } { my $row = $schema->resultset('User')->find(2); is( $row->title, 'mr' ); is( $row->name, 'billy bob' ); is( $row->fullname, 'mr billy bob' ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_delete_true.t0000644000175100017520000000332113262760616024050 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_many_repeatable_delete_true.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # address 1 $u1->create_related( 'addresses' => { address => 'somewhere' } ); } { # user 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); # adresses 2,3,4 $u2->create_related( 'addresses', { address => 'home' } ); $u2->create_related( 'addresses', { address => 'office' } ); $u2->create_related( 'addresses', { address => 'temp' } ); } { # changing address 2 and deleting address 3+4 $form->process( { 'id' => 2, 'name' => 'new nick', 'count' => 3, 'addresses_1.id' => 2, 'addresses_1.address' => 'new home', 'addresses_1.delete' => 1, 'addresses_2.id' => 3, 'addresses_2.address' => 'new office', 'addresses_3.id' => 4, 'addresses_3.address' => 'new office', 'addresses_3.delete' => 1, } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $user = $schema->resultset('User')->find(2); is( $user->name, 'new nick' ); my @add = $user->addresses->all; is( scalar @add, 1 ); is( $add[0]->id, 3 ); is( $add[0]->address, 'new office' ); } HTML-FormFu-Model-DBIC-2.03/t/update/unchecked_not_null_checkbox.t0000644000175100017520000000127013262760616023216 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/basic.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); { my $row = $rs->new_result( { checkbox_col => 'xyzfoo', } ); $row->insert; } # an unchecked Checkbox causes no key/value to be submitted at all # this is a problem for NOT NULL columns # ensure the column's default value gets inserted $form->process( { id => 1, } ); { my $row = $rs->find(1); $form->model->update($row); } { my $row = $rs->find(1); is( $row->checkbox_col, '0' ); } HTML-FormFu-Model-DBIC-2.03/t/update/nested_repeatable_write.yml0000644000175100017520000000072613262760616022730 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Hidden name: sched_count - type: Repeatable nested_name: schedules counter_name: sched_count elements: - type: Hidden name: id - type: Text name: note - type: Hidden name: count - type: Repeatable nested_name: tasks counter_name: count elements: - type: Hidden name: id - type: Text name: detail - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup_unselected.t0000644000175100017520000000252213262760616025336 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/many_to_many_checkboxgroup.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')-> create({ id => 1 }); my $band1; # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'John' } ); # band 1 $band1 = $u1->add_to_bands({ band => 'the beatles' }); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'Paul', } ); # band 2 $u2->add_to_bands({ band => 'wings' }); # band 3 - not used $schema->resultset('Band')->create({ band => 'the kinks' }); # band 1 $u2->add_to_bands($band1); } # currently, # user [2] => bands [2, 1] { $form->process( { id => 2, name => 'Paul McCartney', # no bands - if you unselect all options, # the browser doesn't submit that param at all } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $row = $schema->resultset('User')->find(2); is( $row->name, 'Paul McCartney' ); my @bands = $row->bands->all; is( scalar(@bands), 0 ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_one_select.t0000755000175100017520000000270413262760616020466 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_one_select.yml'); my $schema = new_schema(); $form->stash->{schema} = $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" => 1, } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('Master')->find(3); $form->model->update($row); is($row->user->id, 1); $form->process( { "id" => 3, "text_col" => 'a', "user" => 99, } ); ok( $form->submitted_and_valid ); } { my $row = $schema->resultset('Master')->find(3); $form->model->update($row); is($row->user->id, 1); $form = HTML::FormFu->new; $form->stash->{schema} = $schema; $form->load_config_file('t/update/has_one_select.yml'); $form->model->default_values($row); $form->process; like($form, qr/value="1" selected=/); } HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_delete_true.yml0000644000175100017520000000065213262760616024412 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count elements: - type: Hidden name: id - type: Text name: address - type: Checkbox name: delete model_config: delete_if_true: 1 - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/might_have_delete_if_empty.yml0000644000175100017520000000042613262760616023376 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Block nested_name: note elements: - type: Textarea name: note model_config: delete_if_empty: 1 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/might_have.t0000644000175100017520000000204613262760616017622 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/might_have.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' } ); # note 1 $m2->new_related( 'note', { note => 'zzz' } ); } # rows we're going to use { # master 3 my $m3 = $rs->create( { text_col => 'b' } ); # note 2 $m3->new_related( 'note', { note => 'aaa' } ); } { $form->process( { "id" => 3, "text_col" => 'a', "note.id" => 2, "note.note" => 'abc', } ); my $row = $schema->resultset('Master')->find(3); $form->model->update($row); } { my $row = $schema->resultset('Master')->find(3); is( $row->text_col, 'a' ); my $note = $row->note; is( $note->id, 2 ); is( $note->note, 'abc' ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_one.t0000644000175100017520000000212013262760616017114 0ustar carlcarluse 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/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' ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_one_create.t0000644000175100017520000000176213262760616020452 0ustar carlcarluse 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/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' } ); } { $form->process( { "id" => 3, "text_col" => 'a', "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' ); } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_select_additive.yml0000644000175100017520000000043113262760616023743 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 model_config: additive: 1 options_from_model: 0 link_values: rating: 100 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_repeatable.yml0000644000175100017520000000050313262760616022717 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: bands counter_name: count elements: - type: Hidden name: id - type: Text name: band - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_select.yml0000644000175100017520000000026213262760616022074 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_select.yml0000644000175100017520000000017113262760616021534 0ustar carlcarl--- model_config: resultset: Note elements: - name: id - name: note - name: master type: SelectHTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_create.t0000644000175100017520000000127013262760616021163 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->populate({ elements => [ { name => 'band', }, { type => 'Block', nested_name => 'manager', elements => { name => 'name', } } ] }); my $schema = new_schema(); my $rs = $schema->resultset('Band'); my $band = $rs->new_result({}); $form->process({ band => 'The Foobars', 'manager.name' => 'Mr Foo' }); $form->model('DBIC')->update($band); is($band->band, 'The Foobars'); is($band->manager->name, 'Mr Foo'); HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new.t0000644000175100017520000000330213262760616022337 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_many_repeatable_new.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # address 1 $u1->create_related( 'addresses' => { address => 'somewhere' } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); # address 2 $u2->create_related( 'addresses', { address => 'home' } ); # address 3 $u2->create_related( 'addresses', { address => 'office' } ); } { $form->process( { 'id' => 2, 'name' => 'new nick', 'count' => 3, 'addresses_1.id' => 2, 'addresses_1.address' => 'new home', 'addresses_2.id' => 3, 'addresses_2.address' => 'new office', 'addresses_3.id' => '', 'addresses_3.address' => 'new address', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $user = $schema->resultset('User')->find(2); is( $user->name, 'new nick' ); my @add = $user->addresses->all; is( scalar @add, 3 ); is( $add[0]->id, 2 ); is( $add[0]->address, 'new home' ); is( $add[1]->id, 3 ); is( $add[1]->address, 'new office' ); is( $add[2]->id, 4 ); is( $add[2]->address, 'new address' ); } HTML-FormFu-Model-DBIC-2.03/t/update/nested_create_checkbox.t0000644000175100017520000000114013262760616022154 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/nested.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); # Fake submitted form $form->process( { "foo.id" => 1, "foo.text_col" => 'a', } ); { my $row = $rs->new( {} ); $form->model->update( $row, { nested_base => 'foo' } ); } { my $row = $rs->find(1); is( $row->text_col, 'a' ); # check default is( $row->checkbox_col, 0 ); } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup.yml0000644000175100017520000000025113262760616023456 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Checkboxgroup name: bands - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/might_have.yml0000644000175100017520000000041213262760616020153 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Block nested_name: note elements: - type: Hidden name: id - type: Textarea name: note - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_repeatable.t0000644000175100017520000000274613262760616022374 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/many_to_many_repeatable.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')-> create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # band 1 $u1->add_to_bands({ band => 'a' }); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); # band 2,3,4 $u2->add_to_bands({ band => 'b' }); $u2->add_to_bands({ band => 'c' }); $u2->add_to_bands({ band => 'd' }); } { $form->process( { 'id' => 2, 'name' => 'new nick', 'count' => 2, 'bands_1.id' => 2, 'bands_1.band' => 'b++', 'bands_2.id' => 3, 'bands_2.band' => 'c++', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $user = $schema->resultset('User')->find(2); is( $user->name, 'new nick' ); my @add = $user->bands->all; is( scalar @add, 3 ); is( $add[0]->id, 2 ); is( $add[0]->band, 'b++' ); is( $add[1]->id, 3 ); is( $add[1]->band, 'c++' ); # band 4 should be unchanged is( $add[2]->id, 4 ); is( $add[2]->band, 'd' ); } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup.t0000644000175100017520000000252313262760616023124 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/many_to_many_checkboxgroup.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')-> create({ id => 1 }); my $band1; # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'John' } ); # band 1 $band1 = $u1->add_to_bands({ band => 'the beatles' }); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'Paul', } ); # band 2 $u2->add_to_bands({ band => 'wings' }); # band 3 - not used $schema->resultset('Band')->create({ band => 'the kinks' }); # band 1 $u2->add_to_bands($band1); } # currently, # user [2] => bands [2, 1] { $form->process( { id => 2, name => 'Paul McCartney', bands => [ 1, 3 ], } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $row = $schema->resultset('User')->find(2); is( $row->name, 'Paul McCartney' ); my @bands = $row->bands->all; is( scalar @bands, 2 ); my @id = sort map { $_->id } @bands; is( $id[0], 1 ); is( $id[1], 3 ); } HTML-FormFu-Model-DBIC-2.03/t/update/column_without_field.yml0000644000175100017520000000020413262760616022262 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_create_required.t0000644000175100017520000000127713262760616023072 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->populate({ elements => [ { name => 'band', }, { type => 'Block', nested_name => 'manager', elements => { name => 'name', } } ] }); my $schema = new_schema(); my $rs = $schema->resultset('ManagedBand'); my $band = $rs->new_result({}); $form->process({ band => 'The Foobars', 'manager.name' => 'Mr Foo' }); $form->model('DBIC')->update($band); is($band->band, 'The Foobars'); is($band->manager->name, 'Mr Foo'); HTML-FormFu-Model-DBIC-2.03/t/update/might_have_delete_if_empty.t0000644000175100017520000000226113262760616023037 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/might_have_delete_if_empty.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); my $note_rs = $schema->resultset('Note'); # Fake submitted form $form->process( { "id" => 3, "text_col" => 'a', "note.note" => '', } ); { # insert some entries we'll ignore, so our rels don't have same ids # test id 1 my $t1 = $rs->new_result( { text_col => 'xxx' } ); $t1->insert; # test id 2 my $t2 = $rs->new_result( { text_col => 'yyy' } ); $t2->insert; # note id 1 my $n1 = $t2->new_related( 'note', { note => 'zzz' } ); $n1->insert; # should get master id 3 my $master = $rs->new( { text_col => 'b' } ); $master->insert; # should get note id 2 my $note = $master->new_related( 'note', { note => 'abc' } ); $note->insert; $form->model->update($master); } { my $row = $rs->find(3); is( $row->text_col, 'a' ); my $note = $row->note; ok( !defined $note ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_many_new.t0000644000175100017520000000205613262760616023370 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; use lib qw(t/lib lib); use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_many_repeatable_many_new.yml'); my $schema = new_schema(); my $user_rs = $schema->resultset('User'); my $address_rs = $schema->resultset('Address'); { $form->process( { 'id' => '', 'name' => 'new nick', 'master' => 1, 'count' => 2, 'addresses_1.id' => '', 'addresses_1.address' => 'new home', 'addresses_2.id' => '', 'addresses_2.address' => 'new office', } ); ok( $form->submitted_and_valid ); my $row = $user_rs->new( {} ); $form->model('DBIC')->update($row); my $user = $user_rs->find(1); is( $user->name, 'new nick' ); my @add = $user->addresses->all; is( scalar @add, 2 ); is( $add[0]->id, 1 ); is( $add[0]->address, 'new home' ); is( $add[1]->id, 2 ); is( $add[1]->address, 'new office' ); } HTML-FormFu-Model-DBIC-2.03/t/update/basic.yml0000644000175100017520000000143213262760616017124 0ustar carlcarl--- 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 HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_many_new.yml0000644000175100017520000000065013262760616023724 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Text name: master - type: Repeatable nested_name: addresses counter_name: count model_config: new_rows_max: 2 elements: - type: Hidden name: id - type: Text name: address - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/nested_name_accessor.t0000644000175100017520000000226513262760616021656 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/nested_name_accessor.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'mr. bar', } ); # hasmanys 2,3 $u1->create_related( 'hasmanys', { key => 'bar', value => 'a' } ); $u1->create_related( 'hasmanys', { key => 'foo', value => 'b' } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'mr. foo', } ); # hasmanys 3 4 $u2->create_related( 'hasmanys', { key => 'bar', value => 'c' } ); $u2->create_related( 'hasmanys', { key => 'foo', value => 'd' } ); } { $form->process( { 'name' => 'Mr. Foo', 'foo.value' => 'e', } ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $row = $schema->resultset('User')->find(2); is ( $row->name, 'Mr. Foo' ); is ( $row->foo->value, 'e' ); } HTML-FormFu-Model-DBIC-2.03/t/update/methods.t0000644000175100017520000000214113262760616017146 0ustar carlcarluse 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/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/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); } HTML-FormFu-Model-DBIC-2.03/t/update/basic_update.t0000644000175100017520000000300113262760616020122 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/basic.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); { my $row = $rs->new_result( { text_col => 'xyza', password_col => 'xyzb', checkbox_col => 'xyzfoo', select_col => 'xyz2', combobox_col => 'combo', radio_col => 'xyzyes', radiogroup_col => 'xyz3', array_col => [qw(abc xyz)], } ); $row->insert; } # Fake submitted form $form->process( { id => 1, text_col => 'a', password_col => 'b', checkbox_col => 'foo', select_col => '2', combobox_col_select => '', combobox_col_text => 'txt', radio_col => 'yes', radiogroup_col => '3', array_col => [qw(one two)], } ); { my $row = $rs->find(1); $form->model->update($row); } { my $row = $rs->find(1); is( $row->text_col, 'a' ); is( $row->password_col, 'b' ); is( $row->checkbox_col, 'foo' ); is( $row->combobox_col, 'txt' ); is( $row->select_col, '2' ); is( $row->radio_col, 'yes' ); is( $row->radiogroup_col, '3' ); is( ($row->array_col)->[0], 'one' ); is( ($row->array_col)->[1], 'two' ); } HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_lookup_table_combobox.yml0000644000175100017520000000056113262760616024630 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: ComboBox name: type # set this, so options_from_model() populates the menu, # so we can test the correct default is set model_config: resultset: Type select_column: id text_column: type - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/null_if_empty.yml0000644000175100017520000000022613262760616020711 0ustar carlcarl--- model_config: resultset: User elements: - type: Text name: name - type: Text name: title model_config: null_if_empty: 1 HTML-FormFu-Model-DBIC-2.03/t/update/nested_create.t0000644000175100017520000000212713262760616020314 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/nested.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); # Fake submitted form $form->process( { "foo.id" => 1, "foo.text_col" => 'a', "foo.password_col" => 'b', "foo.checkbox_col" => 'foo', "foo.select_col" => '2', "foo.combobox_col_select" => "", "foo.combobox_col_text" => "combo", "foo.radio_col" => 'yes', "foo.radiogroup_col" => '3', } ); { my $row = $rs->new( {} ); $form->model->update( $row, { nested_base => 'foo' } ); } { my $row = $rs->find(1); is( $row->text_col, 'a' ); is( $row->password_col, 'b' ); is( $row->checkbox_col, 'foo' ); is( $row->select_col, '2' ); is( $row->combobox_col, 'combo' ); is( $row->radio_col, 'yes' ); is( $row->radiogroup_col, '3' ) } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_select.t0000644000175100017520000000251513262760616021541 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/many_to_many_select.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')-> create({ id => 1 }); my $band1; # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'John' } ); # band 1 $band1 = $u1->add_to_bands({ band => 'the beatles' }); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'Paul', } ); # band 2 $u2->add_to_bands({ band => 'wings' }); # band 3 - not used $schema->resultset('Band')->create({ band => 'the kinks' }); # band 1 $u2->add_to_bands($band1); } # currently, # user [2] => bands [2, 1] { $form->process( { id => 2, name => 'Paul McCartney', bands => [ 1, 3 ], } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $row = $schema->resultset('User')->find(2); is( $row->name, 'Paul McCartney' ); my @bands = $row->bands->all; is( scalar @bands, 2 ); my @id = sort map { $_->id } @bands; is( $id[0], 1 ); is( $id[1], 3 ); } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many-has_many.t0000644000175100017520000000612513262760616022000 0ustar carlcarluse strict; use warnings; use Test::More tests => 15; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/many_to_many-has_many.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create( { id => 1 } ); # filler rows { # user 1 my $user = $master->create_related( 'user', { name => 'filler', } ); # band 1 $user->add_to_bands( { band => 'a', } ); # address 1 $user->add_to_addresses( { address => 'b' } ); # user 2,3,4 $master->create_related( 'user', { name => 'filler2', } ); $master->create_related( 'user', { name => 'filler3', } ); $master->create_related( 'user', { name => 'filler4', } ); } # rows we're going to use { # band 2 my $band = $schema->resultset('Band')->create( { band => 'band 2' } ); # user 5,6 my $user1 = $band->add_to_users( { name => 'user 5', master => $master->id } ); my $user2 = $band->add_to_users( { name => 'user 6', master => $master->id } ); # address 2,3 $user1->create_related( 'addresses', { address => 'add 2' } ); $user1->create_related( 'addresses', { address => 'add 3' } ); # address 4 $user2->create_related( 'addresses', { address => 'add 4' } ); } { $form->process( { 'band' => 'band 2 edit', 'count' => 2, 'users_1.id' => 5, 'users_1.name' => 'user 5 edit', 'users_1.count' => 2, 'users_1.addresses_1.id' => 2, 'users_1.addresses_1.address' => 'add 2 edit', 'users_1.addresses_2.id' => 3, 'users_1.addresses_2.address' => 'add 3 edit', 'users_2.id' => 6, 'users_2.name' => 'user 6 edit', 'users_2.count' => 1, 'users_2.addresses_1.id' => 4, 'users_2.addresses_1.address' => 'add 4 edit', 'submit' => 'Submit', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('Band')->find(2); $form->model->update($row); } { my $band = $schema->resultset('Band')->find(2); is( $band->band, 'band 2 edit' ); my @user = $band->users->all; is( scalar @user, 2 ); # user 5 { is( $user[0]->id, 5 ); is( $user[0]->name, 'user 5 edit' ); my @address = $user[0]->addresses->all; is( scalar @address, 2 ); # address 2 is( $address[0]->id, 2 ); is( $address[0]->address, 'add 2 edit' ); # address 3 is( $address[1]->id, 3 ); is( $address[1]->address, 'add 3 edit' ); } # user 6 { is( $user[1]->id, 6 ); is( $user[1]->name, 'user 6 edit' ); my @address = $user[1]->addresses->all; is( scalar @address, 1 ); # address 3 is( $address[0]->id, 4 ); is( $address[0]->address, 'add 4 edit' ); } } HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_combobox.t0000644000175100017520000000171413262760616021533 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/default_values/belongs_to_lookup_table_combobox.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $rs = $schema->resultset('Master'); # filler rows { # insert some entries we'll ignore, so our rels don't have same ids $rs->create( { id => 1 } ); $rs->create( { id => 2 } ); } { # master 3 my $master = $rs->create( { text_col => 'b', type_id => 2, type2_id => 2, } ); # Fake submitted form $form->process( { "id" => 3, "text_col" => 'a', 'type_select' => '1', 'type2_id' => '1', } ); $form->model->update($master); } { my $row = $rs->find(3); is( $row->type->id, '1' ); is( $row->type2->id, '1' ); } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup_restricted.t0000644000175100017520000000306713262760616025360 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use HTMLFormFu::MockContext; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/many_to_many_checkboxgroup_restricted.yml'); my $schema = new_schema(); my $context = HTMLFormFu::MockContext->new( { model => $schema->resultset('Band'), } ); $form->stash( { context => $context } ); my $master = $schema->resultset('Master')->create({ id => 1 }); my $band1; # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'John' } ); # band 1 $band1 = $u1->add_to_bands( { band => 'the beatles', manager => 1 } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'Paul' } ); $u2->add_to_bands($band1); # band 2 $schema->resultset('Band')->create( { band => 'wings', manager => 1 } ); # band 3 $u2->add_to_bands( { band => 'the kinks', manager => 2 } ); } # currently, # user [2] => bands [3, 1] { $form->process( { id => 2, name => 'Paul McCartney', bands => [ 1 ], } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $row = $schema->resultset('User')->find(2); is( $row->name, 'Paul McCartney' ); my @bands = $row->bands->all; is( scalar @bands, 2 ); my @id = sort map { $_->id } @bands; is( $id[0], 1 ); is( $id[1], 3 ); # 3 should not have been touched } HTML-FormFu-Model-DBIC-2.03/t/update/has_one_select.yml0000644000175100017520000000031513262760616021015 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Select name: user model_config: resultset: User - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_dependon.t0000644000175100017520000000357513262760616024227 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_many_repeatable_new_dependon.yml'); # a form is created with 'empty_rows' => 2 # but only 1 new row is filled in # test a DependOn constraint attached to the PK column # with 'others' listing the required fields my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # address 1 $u1->create_related( 'addresses' => { address => 'somewhere' } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); # address 2 $u2->create_related( 'addresses', { address => 'home' } ); # address 3 $u2->create_related( 'addresses', { address => 'office' } ); } { $form->process( { 'id' => 2, 'name' => 'new nick', 'count' => 4, 'addresses_1.id' => 2, 'addresses_1.address' => 'new home', 'addresses_2.id' => 3, 'addresses_2.address' => 'new office', 'addresses_3.id' => '', 'addresses_3.address' => 'new address', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $user = $schema->resultset('User')->find(2); is( $user->name, 'new nick' ); my @add = $user->addresses->all; is( scalar @add, 3 ); is( $add[0]->id, 2 ); is( $add[0]->address, 'new home' ); is( $add[1]->id, 3 ); is( $add[1]->address, 'new office' ); is( $add[2]->id, 4 ); is( $add[2]->address, 'new address' ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_required_when.yml0000644000175100017520000000073513262760616025625 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count model_config: empty_rows: 2 elements: - type: Hidden name: id - type: Text name: address constraints: - type: Required when: field: 'addresses.id' - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_date.yml0000644000175100017520000000075113262760616023677 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Text name: text_col - type: Repeatable nested_name: schedules counter_name: count model_config: empty_rows: 1 new_rows_max: 1 elements: - type: Hidden name: id - type: Date name: date auto_inflate: 1 constraints: - Required - name: note constraints: - Required - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/nested.yml0000644000175100017520000000130713262760616017326 0ustar carlcarl--- auto_fieldset: nested_name: foo 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: Text name: date_col - type: Text name: unknown_col - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_select_two.yml0000644000175100017520000000020113262760616022417 0ustar carlcarl--- model_config: resultset: TwoNote elements: - name: two_note_id - name: note - name: id type: SelectHTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_select.t0000644000175100017520000000234613262760616021204 0ustar carlcarluse 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/update/belongs_to_select.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $rs = $schema->resultset('Master'); $rs->create( { id => 1 } ); $rs->create( { id => 2 } ); my $master = $rs->create( { text_col => 'b', type_id => 2, type2_id => 2 } ); $form->process( { master => 2, note => 'foo' } ); $form->model->create; my $note = $schema->resultset("Note")->find(1); is($note->master->id, 2); is($note->note, 'foo'); } { my $form = HTML::FormFu->new; $form->load_config_file('t/update/belongs_to_select_two.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $rs = $schema->resultset('Master'); $rs->create( { id => 4 } ); $rs->create( { id => 5 } ); my $master = $rs->create( { text_col => 'b', type_id => 2, type2_id => 2 } ); $form->process( { id => 4, note => 'foo' } ); $form->model->create; my $note = $schema->resultset("TwoNote")->find(1); is($note->id->id, 4); is($note->note, 'foo'); } HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_date.t0000644000175100017520000000353613262760616023345 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; use DateTime; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_many_repeatable_new_date.yml'); my $schema = new_schema(); my $master_rs = $schema->resultset('Master'); # filler rows { # user 1 my $m1 = $master_rs->create( { text_col => 'foo' } ); # schedule 1 $m1->create_related( 'schedules', { date => DateTime->new( year => 2008, month => 7, day => 16 ), note => 'a', } ); # schedule 2 $m1->create_related( 'schedules', { date => DateTime->new( year => 2008, month => 7, day => 17 ), note => 'b', } ); } # rows we're going to use { # user 2 my $m2 = $master_rs->create( { text_col => 'orig text', } ); # schedule 3 $m2->create_related( 'schedules', { date => DateTime->new( year => 2008, month => 7, day => 18 ), note => 'c', } ); } { $form->process( { 'text_col' => 'new text', 'count' => 1, 'schedules_1.id' => 3, 'schedules_1.date_day' => '19', 'schedules_1.date_month' => '07', 'schedules_1.date_year' => '2008', 'schedules_1.note' => 'hi', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('Master')->find(2); $form->model->update($row); } { my $user = $schema->resultset('Master')->find(2); is( $user->text_col, 'new text' ); my @schedule = $user->schedules->all; is( scalar @schedule, 1 ); is( $schedule[0]->id, 3 ); my $date = $schedule[0]->date; isa_ok( $date, 'DateTime' ); is( $date->year, 2008 ); is( $date->month, 7 ); is( $date->day, 19 ); is( $schedule[0]->note, 'hi' ); } HTML-FormFu-Model-DBIC-2.03/t/update/null_if_empty.t0000644000175100017520000000221113262760616020347 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/null_if_empty.yml'); my $schema = new_schema(); my $rs = $schema->resultset('User')->create( { name => "foo", } ); is( $rs->name, "foo" ); { $form->process( { name => "foo", title => "" } ); $form->model->update($rs); is( $rs->title, undef ); } { $form->process( { name => "foo", title => 'test' } ); $form->model->update($rs); is( $rs->title, "test" ); } { $form->process( { name => "foo", title => undef } ); $form->model->update($rs); is( $rs->title, undef ); } { $form->process( { name => "foo", title => 0 } ); $form->model->update($rs); is( $rs->title, "0" ); } { $form->process( { name => "foo", title => " " } ); $form->model->update($rs); is( $rs->title, " " ); } { $form->get_element( name => 'title' )->model_config->{null_if_empty} = 0; $form->process( { name => "foo", title => "" } ); $form->model->update($rs); is( $rs->title, "" ); } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup_read_only.t0000644000175100017520000000252413262760616025161 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/many_to_many_checkboxgroup_read_only.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')-> create({ id => 1 }); my $band1; # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'John' } ); # band 1 $band1 = $u1->add_to_bands({ band => 'the beatles' }); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'Paul', } ); # band 2 $u2->add_to_bands({ band => 'wings' }); # band 3 - not used $schema->resultset('Band')->create({ band => 'the kinks' }); # band 1 $u2->add_to_bands($band1); } # currently, # user [2] => bands [2, 1] { $form->process( { id => 2, name => 'John Lennon', bands => [ 2 ], } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $row = $schema->resultset('User')->find(2); is( $row->name, 'John Lennon' ); my @bands = $row->bands->all; is( scalar @bands, 2 ); my @id = sort map { $_->id } @bands; is( $id[0], 1 ); is( $id[1], 2 ); } HTML-FormFu-Model-DBIC-2.03/t/update/column_without_field.t0000644000175100017520000000144313262760616021732 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/column_without_field.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); { my $row = $rs->new_result( { text_col => 'a', password_col => 'd', checkbox_col => 'g' } ); $row->insert; } # Fake submitted form $form->process( { id => 1, text_col => 'abc', } ); { my $row = $rs->find(1); $form->model->update($row); } { my $row = $rs->find(1); is( $row->text_col, 'abc' ); # original values still there is( $row->password_col, 'd' ); is( $row->checkbox_col, 'g' ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new.yml0000644000175100017520000000060713262760616022702 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count model_config: empty_rows: 1 new_rows_max: 1 elements: - type: Hidden name: id - type: Text name: address - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/nested_repeatable_write.t0000644000175100017520000000360613262760616022372 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/nested_repeatable_write.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # first sub-record { # schedule 1 my $u1 = $master->create_related( 'schedules', { note => 'some appointment', date => '02-02-2009' } ); # task 1 $u1->create_related( 'tasks' => { detail => 'associated to do item' } ); } # second sub-record { # schedule 2 my $u2 = $master->create_related( 'schedules', { note => 'some other appointment', date => '03-03-2009' } ); # task 2 $u2->create_related( 'tasks', { detail => 'action item 1' } ); # task 3 $u2->create_related( 'tasks', { detail => 'action item 2' } ); } { $form->process( { 'sched_count' => 2, 'schedules_2.id' => 2, 'schedules_2.note' => 'new appointment', 'schedules_2.count' => 2, 'schedules_2.tasks_1.id' => 2, 'schedules_2.tasks_1.detail' => 'new action item 1', 'schedules_2.tasks_2.id' => 3, 'schedules_2.tasks_2.detail' => 'new action item 2', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('Master')->find(1); $form->model->update($row); } { my $schedule = $schema->resultset('Schedule')->find(2); is( $schedule->note, 'new appointment' ); my @add = $schedule->tasks->all; is( scalar @add, 2 ); is( $add[0]->id, 2 ); is( $add[0]->detail, 'new action item 1' ); is( $add[1]->id, 3 ); is( $add[1]->detail, 'new action item 2' ); } HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_select_unselected.t0000644000175100017520000000251313262760616023752 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/many_to_many_select.yml'); my $schema = new_schema(); my $master = $schema->resultset('Master')-> create({ id => 1 }); my $band1; # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'John' } ); # band 1 $band1 = $u1->add_to_bands({ band => 'the beatles' }); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'Paul', } ); # band 2 $u2->add_to_bands({ band => 'wings' }); # band 3 - not used $schema->resultset('Band')->create({ band => 'the kinks' }); # band 1 $u2->add_to_bands($band1); } # currently, # user [2] => bands [2, 1] { $form->process( { id => 2, name => 'Paul McCartney', # no bands - if you unselect all options, # the browser doesn't submit that param at all } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $row = $schema->resultset('User')->find(2); is( $row->name, 'Paul McCartney' ); my @bands = $row->bands->all; is( scalar(@bands), 0 ); } HTML-FormFu-Model-DBIC-2.03/t/update/might_have_create.t0000644000175100017520000000215413262760616021145 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/might_have.yml'); my $schema = new_schema(); my $rs = $schema->resultset('Master'); my $note_rs = $schema->resultset('Note'); # Fake submitted form $form->process( { "id" => 3, "text_col" => 'a', "note.note" => 'abc', } ); { # insert some entries we'll ignore, so our rels don't have same ids # test id 1 my $t1 = $rs->new_result( { text_col => 'xxx' } ); $t1->insert; # test id 2 my $t2 = $rs->new_result( { text_col => 'yyy' } ); $t2->insert; # note id 1 my $n1 = $t2->new_related( 'note', { note => 'zzz' } ); $n1->insert; # should get test id 3 my $master = $rs->new( { text_col => 'b' } ); $master->insert; # no note, but next id 2 $form->model->update($master); } { my $row = $rs->find(3); is( $row->text_col, 'a' ); my $note = $row->note; is( $note->id, 2 ); is( $note->note, 'abc' ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_implicit.t0000644000175100017520000000342513262760616024237 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/update/has_many_repeatable_new_implicit.yml'); # config file doesn't set 'new_rows_max' so 'empty_rows' is used instead my $schema = new_schema(); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'foo' } ); # address 1 $u1->create_related( 'addresses' => { address => 'somewhere' } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'nick', } ); # address 2 $u2->create_related( 'addresses', { address => 'home' } ); # address 3 $u2->create_related( 'addresses', { address => 'office' } ); } { $form->process( { 'id' => 2, 'name' => 'new nick', 'count' => 3, 'addresses_1.id' => 2, 'addresses_1.address' => 'new home', 'addresses_2.id' => 3, 'addresses_2.address' => 'new office', 'addresses_3.id' => '', 'addresses_3.address' => 'new address', } ); ok( $form->submitted_and_valid ); my $row = $schema->resultset('User')->find(2); $form->model->update($row); } { my $user = $schema->resultset('User')->find(2); is( $user->name, 'new nick' ); my @add = $user->addresses->all; is( scalar @add, 3 ); is( $add[0]->id, 2 ); is( $add[0]->address, 'new home' ); is( $add[1]->id, 3 ); is( $add[1]->address, 'new office' ); is( $add[2]->id, 4 ); is( $add[2]->address, 'new address' ); } HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_lookup_table_combobox.t0000644000175100017520000000304513262760616024272 0ustar carlcarluse 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/update/belongs_to_lookup_table_combobox.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $rs = $schema->resultset('Master'); # filler rows { # insert some entries we'll ignore, so our rels don't have same ids $rs->create( { id => 1 } ); $rs->create( { id => 2 } ); # types my $type_rs = $schema->resultset('Type'); $type_rs->delete; $type_rs->create( { type => 'type 1' } ); $type_rs->create( { type => 'type 2' } ); $type_rs->create( { type => 'type 3' } ); } # master 3 my $master = $rs->create( { text_col => 'aaa' } ); { # submit combobox select ID $form->process( { "id" => 3, "text_col" => 'bbb', "type_select" => '2', "type_text" => '', } ); $form->model->update($master); my $row = $rs->find(3); is( $row->text_col, 'bbb'); is( $row->type->id, 2 ); is( $row->type->type, 'type 2' ); } { # submit combobox text field # will create a new 'type' related row $form->process( { "id" => 3, "text_col" => 'ccc', "type_select" => '', "type_text" => 'type 4', } ); $form->model->update($master); my $row = $rs->find(3); is( $row->text_col, 'ccc'); is( $row->type->id, 4 ); is( $row->type->type, 'type 4' ); } HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_dependon.yml0000644000175100017520000000070113262760616024551 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Repeatable nested_name: addresses counter_name: count model_config: empty_rows: 2 elements: - type: Hidden name: id constraints: - type: DependOn others: address - type: Text name: address - type: Hidden name: count - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/update/has_one_no_id.t0000644000175100017520000000177013262760616020276 0ustar carlcarluse 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/update/has_one_no_id.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' } ); } { $form->process( { "id" => 3, "text_col" => 'a', "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' ); } HTML-FormFu-Model-DBIC-2.03/t/00-report-prereqs.t0000644000175100017520000001342613262760616017440 0ustar carlcarl#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.027 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: HTML-FormFu-Model-DBIC-2.03/t/create/0000775000175100017520000000000013262760616015303 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/create/basic.yml0000644000175100017520000000115113262760616017103 0ustar carlcarl--- 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 HTML-FormFu-Model-DBIC-2.03/t/create/basic.t0000644000175100017520000000161613262760616016553 0ustar carlcarluse 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/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' ) } HTML-FormFu-Model-DBIC-2.03/t/lib/0000775000175100017520000000000013262760616014606 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/lib/HTMLFormFu/0000775000175100017520000000000013262760616016471 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/lib/HTMLFormFu/I18N.pm0000644000175100017520000000026313262760616017505 0ustar carlcarlpackage HTMLFormFu::I18N; use strict; use warnings; use base 'Locale::Maketext'; *loc = \&localize; sub localize { my $self = shift; return $self->maketext(@_); } 1; HTML-FormFu-Model-DBIC-2.03/t/lib/HTMLFormFu/MockContext.pm0000644000175100017520000000031613262760616021263 0ustar carlcarlpackage HTMLFormFu::MockContext; use strict; use warnings; sub new { my ( $class, $args ) = @_; return bless $args, $class; } sub model { my ( $self ) = @_; return $self->{model} } 1; HTML-FormFu-Model-DBIC-2.03/t/lib/HTMLFormFu/I18N/0000775000175100017520000000000013262760616017150 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/lib/HTMLFormFu/I18N/en.pm0000644000175100017520000000024313262760616020105 0ustar carlcarlpackage HTMLFormFu::I18N::en; use strict; use warnings; use base qw( HTMLFormFu::I18N ); our %Lexicon = ( label_foo => 'Foo', label_bar => 'Bar', ); 1; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/0000775000175100017520000000000013262760616016314 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Band.pm0000644000175100017520000000111613262760616017513 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/User.pm0000644000175100017520000000274113262760616017572 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Task.pm0000644000175100017520000000101713262760616017551 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/TwoNote.pm0000644000175100017520000000074713262760616020257 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Type2.pm0000644000175100017520000000051613262760616017655 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Address.pm0000644000175100017520000000101513262760616020232 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/ManagedBand.pm0000644000175100017520000000116713262760616020776 0ustar carlcarlpackage MySchema::ManagedBand; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/ Core /); __PACKAGE__->table("managed_band"); __PACKAGE__->add_columns( id => { data_type => "INTEGER", is_nullable => 0 }, manager_id => { data_type => "INTEGER", is_nullable => 0 }, band => { data_type => "TEXT", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( manager => 'MySchema::Manager', 'manager_id' ); __PACKAGE__->has_many( user_bands => 'MySchema::UserBand', 'band' ); __PACKAGE__->many_to_many( users => 'user_bands', 'user' ); 1; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Manager.pm0000644000175100017520000000062213262760616020222 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Note.pm0000644000175100017520000000070613262760616017560 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Schedule.pm0000644000175100017520000000114413262760616020404 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/UserBand.pm0000644000175100017520000000111613262760616020352 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/HasMany.pm0000644000175100017520000000071413262760616020212 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Master.pm0000644000175100017520000000455213262760616020111 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Type.pm0000644000175100017520000000051413262760616017571 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema.pm0000644000175100017520000000015613262760616016652 0ustar carlcarlpackage MySchema; use strict; use warnings; use base 'DBIx::Class::Schema'; __PACKAGE__->load_classes; 1; HTML-FormFu-Model-DBIC-2.03/t/lib/DBICTestLib.pm0000644000175100017520000000101413262760616017126 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/lib/MySchemaRS/0000775000175100017520000000000013262760616016561 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/lib/MySchemaRS/User.pm0000644000175100017520000000100713262760616020031 0ustar carlcarlpackage 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; HTML-FormFu-Model-DBIC-2.03/t/options_from_model/0000775000175100017520000000000013262760616017736 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/t/options_from_model/many_to_many_select_restricted.t0000644000175100017520000000320413262760616026401 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use HTMLFormFu::MockContext; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/many_to_many_select_restricted.yml'); my $schema = new_schema(); my $context = HTMLFormFu::MockContext->new( { model => $schema->resultset('Band'), } ); $form->stash( { context => $context } ); my $master = $schema->resultset('Master')->create({ id => 1 }); my $band1; # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'John' } ); # band 1 $band1 = $u1->add_to_bands( { band => 'the beatles', manager => 1 } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'Paul' } ); $u2->add_to_bands($band1); # band 2 $u2->add_to_bands( { band => 'wings', manager => 1 } ); # band 3 $schema->resultset('Band')->create( { band => 'the kinks', manager => 2 } ); } { $form->process; is_deeply( $form->get_field('bands')->options, [ { 'label_attributes' => {}, 'value' => '1', 'label' => 'the beatles', 'attributes' => {}, 'container_attributes' => {}, }, { 'label_attributes' => {}, 'value' => '2', 'label' => 'wings', 'attributes' => {}, 'container_attributes' => {}, }, ], "Options set from the model" ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/constraint_autoset.t0000644000175100017520000000261613262760616024056 0ustar carlcarluse strict; use warnings; use Test::More tests => 11; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/constraint_autoset.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $type_rs = $schema->resultset('Type'); my $type2_rs = $schema->resultset('Type2'); { # types $type_rs->delete; $type_rs->create( { type => 'type 1' } ); $type_rs->create( { type => 'type 2' } ); $type_rs->create( { type => 'type 3' } ); $type2_rs->delete; $type2_rs->create( { type => 'type 1' } ); $type2_rs->create( { type => 'type 2' } ); $type2_rs->create( { type => 'type 3' } ); } $form->process({ type => 2, type2_id => 4, }); { my $option = $form->get_field('type')->options; ok( @$option == 3 ); is( $option->[0]->{label}, 'type 1' ); is( $option->[1]->{label}, 'type 2' ); is( $option->[2]->{label}, 'type 3' ); } { my $option = $form->get_field('type2_id')->options; ok( @$option == 3 ); is( $option->[0]->{label}, 'type 1' ); is( $option->[1]->{label}, 'type 2' ); is( $option->[2]->{label}, 'type 3' ); } # ensure the options are set in time for the AutoSet constraint to work ok( $form->valid('type') ); ok( !$form->valid('type2_id') ); is_deeply( $form->params, { type => 2, } ); HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_config_zero_combobox.yml0000644000175100017520000000032513262760616027066 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: ComboBox name: type model_config: options_from_model: 0 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_complex.t0000644000175100017520000000223513262760616026065 0ustar carlcarluse 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/options_from_model/condition_from_stash.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $master_rs = $schema->resultset('Master'); my $user_rs = $schema->resultset('User'); { my $m1 = $master_rs->create({ text_col => 'foo' }); $m1->create_related( 'user', { name => 'a' } ); $m1->create_related( 'user', { name => 'b' } ); $m1->create_related( 'user', { name => 'c' } ); } { my $m2 = $master_rs->create({ text_col => 'bar' }); $m2->create_related( 'user', { name => 'd' } ); $m2->create_related( 'user', { name => 'e' } ); $m2->create_related( 'user', { name => 'f' } ); $m2->create_related( 'user', { name => 'g' } ); } # master_id contains a complex condition $form->stash->{master_id} = {'!=' => '2' }; $form->process; { my $option = $form->get_field('user')->options; ok( @$option == 3 ); is( $option->[0]->{label}, 'a' ); is( $option->[1]->{label}, 'b' ); is( $option->[2]->{label}, 'c' ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_localize_label.yml0000644000175100017520000000031713262760616025634 0ustar carlcarl--- auto_fieldset: 1 localize_class: 'HTMLFormFu::I18N' elements: - type: Hidden name: id - type: Select name: type model_config: localize_label: 1 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to.t0000644000175100017520000000222213262760616022252 0ustar carlcarluse strict; use warnings; use Test::More tests => 8; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/belongs_to.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $type_rs = $schema->resultset('Type'); my $type2_rs = $schema->resultset('Type2'); { # types $type_rs->delete; $type_rs->create( { type => 'type 1' } ); $type_rs->create( { type => 'type 2' } ); $type_rs->create( { type => 'type 3' } ); $type2_rs->delete; $type2_rs->create( { type => 'type 1' } ); $type2_rs->create( { type => 'type 2' } ); $type2_rs->create( { type => 'type 3' } ); } $form->process; { my $option = $form->get_field('type')->options; ok( @$option == 3 ); is( $option->[0]->{label}, 'type 1' ); is( $option->[1]->{label}, 'type 2' ); is( $option->[2]->{label}, 'type 3' ); } { my $option = $form->get_field('type2_id')->options; ok( @$option == 3 ); is( $option->[0]->{label}, 'type 1' ); is( $option->[1]->{label}, 'type 2' ); is( $option->[2]->{label}, 'type 3' ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_combobox.yml0000644000175100017520000000024013262760616026556 0ustar carlcarl--- auto_fieldset: 1 elements: - type: ComboBox name: user model_config: resultset: User condition_from_stash: master: master_id HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_combobox_complex.t0000644000175100017520000000231113262760616027750 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/condition_from_stash_combobox.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $master_rs = $schema->resultset('Master'); my $user_rs = $schema->resultset('User'); { my $m1 = $master_rs->create({ text_col => 'foo' }); $m1->create_related( 'user', { name => 'a' } ); $m1->create_related( 'user', { name => 'b' } ); $m1->create_related( 'user', { name => 'c' } ); } { my $m2 = $master_rs->create({ text_col => 'bar' }); $m2->create_related( 'user', { name => 'd' } ); $m2->create_related( 'user', { name => 'e' } ); $m2->create_related( 'user', { name => 'f' } ); $m2->create_related( 'user', { name => 'g' } ); } # master_id contains complex condition $form->stash->{master_id} = {'!=' => '2' }; $form->process; { my $option = $form->get_field('user')->options; ok( @$option == 4 ); is( $option->[0]->{label}, '' ); is( $option->[1]->{label}, 'a' ); is( $option->[2]->{label}, 'b' ); is( $option->[3]->{label}, 'c' ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/enum_select.yml0000644000175100017520000000041713262760616022764 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Select name: enum_col model_config: options_from_model: 1 resultset: Master constraint: - AutoSet - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_config_zero_combobox.t0000644000175100017520000000163213262760616026532 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/belongs_to_config_zero_combobox.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $type_rs = $schema->resultset('Type'); my $type2_rs = $schema->resultset('Type2'); { # types $type_rs->delete; $type_rs->create( { type => 'type 1' } ); $type_rs->create( { type => 'type 2' } ); $type_rs->create( { type => 'type 3' } ); $type2_rs->delete; $type2_rs->create( { type => 'type 1' } ); $type2_rs->create( { type => 'type 2' } ); $type2_rs->create( { type => 'type 3' } ); } $form->process; # options() isn't set, because we explicitly set options_from_model to 0 { my $option = $form->get_field('type')->options; is( scalar @$option, 0 ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/enum_select.t0000644000175100017520000000150113262760616022421 0ustar carlcarluse 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/options_from_model/enum_select.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $master_rs = $schema->resultset('Master'); $form->process; { my $option = $form->get_field('enum_col')->options; is( scalar( @$option ), 3 ); is( $option->[0]->{label}, 'a' ); is( $option->[1]->{label}, 'b' ); is( $option->[2]->{label}, 'c' ); } # ensure the options are set in time for the AutoSet constraint to work { $form->process({ enum_col => 'a', }); ok( $form->valid('enum_col') ); } { $form->process({ enum_col => 'd', }); ok( ! $form->valid('enum_col') ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_combobox.t0000644000175100017520000000324213262760616026225 0ustar carlcarluse strict; use warnings; use Test::More tests => 11; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/condition_from_stash_combobox.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $master_rs = $schema->resultset('Master'); my $user_rs = $schema->resultset('User'); { my $m1 = $master_rs->create({ text_col => 'foo' }); $m1->create_related( 'user', { name => 'a' } ); $m1->create_related( 'user', { name => 'b' } ); $m1->create_related( 'user', { name => 'c' } ); } { my $m2 = $master_rs->create({ text_col => 'bar' }); $m2->create_related( 'user', { name => 'd' } ); $m2->create_related( 'user', { name => 'e' } ); $m2->create_related( 'user', { name => 'f' } ); $m2->create_related( 'user', { name => 'g' } ); # master_id contains unique id $form->stash->{master_id} = $m2->id; } $form->process; { my $option = $form->get_field('user')->options; ok( @$option == 5 ); is( $option->[0]->{label}, '' ); is( $option->[1]->{label}, 'd' ); is( $option->[2]->{label}, 'e' ); is( $option->[3]->{label}, 'f' ); is( $option->[4]->{label}, 'g' ); } $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/condition_from_stash_combobox.yml'); $form->stash->{schema} = $schema; $form->stash->{master_id} = {'!=' => '2' }; $form->process; { my $option = $form->get_field('user')->options; ok( @$option == 4 ); is( $option->[0]->{label}, '' ); is( $option->[1]->{label}, 'a' ); is( $option->[2]->{label}, 'b' ); is( $option->[3]->{label}, 'c' ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/has_many_repeatable_select.yml0000644000175100017520000000062013262760616025777 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Hidden name: count - type: Repeatable nested_name: bands counter_name: count elements: - type: Hidden name: id - name: band - type: Checkboxgroup name: users model_config: resultset: User - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_expand.yml0000644000175100017520000000027113262760616026231 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Select name: user model_config: resultset: User condition_from_stash: master: foo.bar.0 expand_stash_dots: 1 HTML-FormFu-Model-DBIC-2.03/t/options_from_model/many_to_many_select.yml0000644000175100017520000000032713262760616024512 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 model_config: model: Bands - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_localize_label.t0000644000175100017520000000123513262760616025276 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/belongs_to_localize_label.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $type_rs = $schema->resultset('Type'); { # types $type_rs->delete; $type_rs->create( { type => 'label_foo' } ); $type_rs->create( { type => 'label_bar' } ); } $form->process; { my $option = $form->get_field('type')->options; ok( @$option == 2 ); is( $option->[0]->{label}, 'Foo' ); is( $option->[1]->{label}, 'Bar' ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/constraint_autoset.yml0000644000175100017520000000054113262760616024407 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Select name: type model_config: options_from_model: 1 constraint: - AutoSet - type: Select name: type2_id model_config: resultset: Type2 constraint: - AutoSet - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/options_from_model/many_to_many_select.t0000644000175100017520000000351613262760616024157 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use HTMLFormFu::MockContext; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/many_to_many_select.yml'); my $schema = new_schema(); my $context = HTMLFormFu::MockContext->new( { model => $schema->resultset('Band'), } ); $form->stash( { context => $context } ); my $master = $schema->resultset('Master')->create({ id => 1 }); my $band1; # filler rows { # user 1 my $u1 = $master->create_related( 'user', { name => 'John' } ); # band 1 $band1 = $u1->add_to_bands( { band => 'the beatles' } ); } # rows we're going to use { # user 2 my $u2 = $master->create_related( 'user', { name => 'Paul' } ); $u2->add_to_bands($band1); # band 2 $u2->add_to_bands( { band => 'wings' } ); # band 3 $schema->resultset('Band')->create( { band => 'the kinks' } ); } { $form->process; is_deeply( $form->get_field('bands')->options, [ { 'label_attributes' => {}, 'value' => '1', 'label' => 'the beatles', 'attributes' => {}, 'container_attributes' => {}, }, { 'label_attributes' => {}, 'value' => '2', 'label' => 'wings', 'attributes' => {}, 'container_attributes' => {}, }, { 'label_attributes' => {}, 'value' => '3', 'label' => 'the kinks', 'attributes' => {}, 'container_attributes' => {}, }, ], "Options set from the model" ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/has_many_repeatable_select.t0000644000175100017520000000643713262760616025455 0ustar carlcarluse strict; use warnings; use Test::More tests => 34; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/has_many_repeatable_select.yml'); my $schema = new_schema(); $form->stash( { schema => $schema } ); my $master = $schema->resultset('Master')->create({ id => 1 }); # filler rows { # user 1, 2 $master->create_related( 'user', { name => 'user 1' } ); $master->create_related( 'user', { name => 'user 2' } ); } # rows we're going to use { # manager 1 my $manager = $schema->resultset('Manager')->create({ name => 'manager 1' }); # band 1, 2 my $band1 = $manager->create_related( 'bands', { band => 'band 1' } ); my $band2 = $manager->create_related( 'bands', { band => 'band 2' } ); # user 3, 4 $band1->add_to_users({ name => 'user 3', master => $manager->id }); $band1->add_to_users({ name => 'user 4', master => $manager->id }); # user 5 $band2->add_to_users({ name => 'user 5', master => $manager->id }); } { $form->process; my $manager = $schema->resultset('Manager')->find(1); $form->model->default_values( $manager ); is( $form->get_field('id')->default, '1' ); is( $form->get_field('name')->default, 'manager 1' ); is( $form->get_field('count')->default, '2' ); my $bands_repeatable = $form->get_all_element({ nested_name => 'bands' }); my @bands = @{ $bands_repeatable->get_elements }; is( scalar @bands, 2 ); # band 1 { is( $bands[0]->nested_name, 'bands_1' ); is( $bands[0]->get_field('id')->default, '1' ); is( $bands[0]->get_field('band')->default, 'band 1' ); # user 3 my $select = $bands[0]->get_field('users'); is_deeply( $select->default, [3, 4] ); is( scalar @{ $select->options }, 5 ); is( $select->options->[0]->{value}, '1' ); is( $select->options->[0]->{label}, 'user 1' ); is( $select->options->[1]->{value}, '2' ); is( $select->options->[1]->{label}, 'user 2' ); is( $select->options->[2]->{value}, '3' ); is( $select->options->[2]->{label}, 'user 3' ); is( $select->options->[3]->{value}, '4' ); is( $select->options->[3]->{label}, 'user 4' ); is( $select->options->[4]->{value}, '5' ); is( $select->options->[4]->{label}, 'user 5' ); } # band 2 { is( $bands[1]->nested_name, 'bands_2' ); is( $bands[1]->get_field('id')->default, '2' ); is( $bands[1]->get_field('band')->default, 'band 2' ); # user 3 my $select = $bands[1]->get_field('users'); is_deeply( $select->default, [5] ); is( scalar @{ $select->options }, 5 ); is( $select->options->[0]->{value}, '1' ); is( $select->options->[0]->{label}, 'user 1' ); is( $select->options->[1]->{value}, '2' ); is( $select->options->[1]->{label}, 'user 2' ); is( $select->options->[2]->{value}, '3' ); is( $select->options->[2]->{label}, 'user 3' ); is( $select->options->[3]->{value}, '4' ); is( $select->options->[3]->{label}, 'user 4' ); is( $select->options->[4]->{value}, '5' ); is( $select->options->[4]->{label}, 'user 5' ); } } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash.t0000644000175100017520000000304213262760616024333 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/condition_from_stash.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $master_rs = $schema->resultset('Master'); my $user_rs = $schema->resultset('User'); { my $m1 = $master_rs->create({ text_col => 'foo' }); $m1->create_related( 'user', { name => 'a' } ); $m1->create_related( 'user', { name => 'b' } ); $m1->create_related( 'user', { name => 'c' } ); } { my $m2 = $master_rs->create({ text_col => 'bar' }); $m2->create_related( 'user', { name => 'd' } ); $m2->create_related( 'user', { name => 'e' } ); $m2->create_related( 'user', { name => 'f' } ); $m2->create_related( 'user', { name => 'g' } ); $form->stash->{master_id} = $m2->id; } $form->process; { my $option = $form->get_field('user')->options; ok( @$option == 4 ); is( $option->[0]->{label}, 'd' ); is( $option->[1]->{label}, 'e' ); is( $option->[2]->{label}, 'f' ); is( $option->[3]->{label}, 'g' ); } $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/condition_from_stash.yml'); $form->stash->{schema} = $schema; $form->stash->{master_id} = {'!=' => '2' }; $form->process; { my $option = $form->get_field('user')->options; ok( @$option == 3 ); is( $option->[0]->{label}, 'a' ); is( $option->[1]->{label}, 'b' ); is( $option->[2]->{label}, 'c' ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_combobox.t0000644000175100017520000000250213262760616024143 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/belongs_to_combobox.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $type_rs = $schema->resultset('Type'); my $type2_rs = $schema->resultset('Type2'); { # types $type_rs->delete; $type_rs->create( { type => 'type 1' } ); $type_rs->create( { type => 'type 2' } ); $type_rs->create( { type => 'type 3' } ); $type2_rs->delete; $type2_rs->create( { type => 'type 1' } ); $type2_rs->create( { type => 'type 2' } ); $type2_rs->create( { type => 'type 3' } ); } $form->process; is( $form->get_field('type'), qq{
} ); is( $form->get_field('type2_id'), qq{
} ); HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to.yml0000644000175100017520000000042513262760616022613 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Select name: type model_config: aaa : aaa - type: Select name: type2_id model_config: resultset: Type2 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash.yml0000644000175100017520000000023613262760616024673 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Select name: user model_config: resultset: User condition_from_stash: master: master_id HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_config_zero.t0000644000175100017520000000162113262760616024640 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; use DBICTestLib 'new_schema'; use MySchema; my $form = HTML::FormFu->new; $form->load_config_file('t/options_from_model/belongs_to_config_zero.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $type_rs = $schema->resultset('Type'); my $type2_rs = $schema->resultset('Type2'); { # types $type_rs->delete; $type_rs->create( { type => 'type 1' } ); $type_rs->create( { type => 'type 2' } ); $type_rs->create( { type => 'type 3' } ); $type2_rs->delete; $type2_rs->create( { type => 'type 1' } ); $type2_rs->create( { type => 'type 2' } ); $type2_rs->create( { type => 'type 3' } ); } $form->process; # options() isn't set, because we explicitly set options_from_model to 0 { my $option = $form->get_field('type')->options; is( scalar @$option, 0 ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_combobox.yml0000644000175100017520000000043113262760616024500 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: ComboBox name: type model_config: aaa : aaa - type: ComboBox name: type2_id model_config: resultset: Type2 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_expand.t0000644000175100017520000000230213262760616025670 0ustar carlcarluse 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/options_from_model/condition_from_stash.yml'); my $schema = new_schema(); $form->stash->{schema} = $schema; my $master_rs = $schema->resultset('Master'); my $user_rs = $schema->resultset('User'); { my $m1 = $master_rs->create({ text_col => 'foo' }); $m1->create_related( 'user', { name => 'a' } ); $m1->create_related( 'user', { name => 'b' } ); $m1->create_related( 'user', { name => 'c' } ); } { my $m2 = $master_rs->create({ text_col => 'bar' }); $m2->create_related( 'user', { name => 'd' } ); $m2->create_related( 'user', { name => 'e' } ); $m2->create_related( 'user', { name => 'f' } ); $m2->create_related( 'user', { name => 'g' } ); $form->stash->{foo}{bar}[0] = $m2->id; } $form->stash->{schema} = $schema; $form->stash->{master_id} = {'!=' => '2' }; $form->process; { my $option = $form->get_field('user')->options; ok( @$option == 3 ); is( $option->[0]->{label}, 'a' ); is( $option->[1]->{label}, 'b' ); is( $option->[2]->{label}, 'c' ); } HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_config_zero.yml0000644000175100017520000000032313262760616025174 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Select name: type model_config: options_from_model: 0 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/t/options_from_model/many_to_many_select_restricted.yml0000644000175100017520000000037313262760616026743 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 model_config: model: Bands condition: manager: 1 - type: Submit name: submit HTML-FormFu-Model-DBIC-2.03/Changes0000644000175100017520000001147313262760616015074 0ustar carlcarl2.03 2018-04-09 21:56:26+00:00 UTC - New 'expand_stash_dots' config option - remove bundled/renamed MooseX::Attribute::Chained and depend on the fixed version 2.02 2016-06-24 - documentation fixes - build and packaging tweaks, including travis CI config, additional author tests, packaging etc 2.00 2014-05-05 - switch from MooseX::Attribute::Chained to MooseX::Attribute::FormFuChained 1.01 2014-01-06 - don't "use" optional modules in tests 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 HTML-FormFu-Model-DBIC-2.03/META.yml0000644000175100017520000002541213262760616015050 0ustar carlcarl--- abstract: 'Integrate HTML::FormFu with DBIx::Class' author: - 'Carl Franks ' build_requires: DateTime::Format::SQLite: '0' ExtUtils::MakeMaker: '0' File::Spec: '0' Locale::Maketext: '0' SQL::Translator: '0.11016' Test::More: '0.99' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.011, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: HTML-FormFu-Model-DBIC no_index: directory: - eg - examples - inc - share - t - xt provides: HTML::FormFu::Constraint::DBIC::Unique: file: lib/HTML/FormFu/Constraint/DBIC/Unique.pm version: '2.03' HTML::FormFu::Model::DBIC: file: lib/HTML/FormFu/Model/DBIC.pm version: '2.03' requires: DBD::SQLite: '0' DBIx::Class: '0.08108' HTML::FormFu: '2.00' List::MoreUtils: '0' MooseX::Attribute::Chained: v1.0.2 Storable: '0' Task::Weaken: '0' perl: '5.008001' resources: homepage: https://github.com/FormFu/HTML-FormFu-Model-DBIC repository: https://github.com/FormFu/HTML-FormFu-Model-DBIC.git version: '2.03' x_Dist_Zilla: perl: version: '5.014004' plugins: - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: runtime type: requires name: Prereqs version: '6.011' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: TestRequires version: '6.011' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: develop type: requires name: DevelopRequires version: '6.011' - class: Dist::Zilla::Plugin::Test::Perl::Critic name: Test::Perl::Critic version: '3.001' - class: Dist::Zilla::Plugin::MetaTests name: MetaTests version: '6.011' - class: Dist::Zilla::Plugin::OurPkgVersion name: OurPkgVersion version: '0.12' - class: Dist::Zilla::Plugin::PodVersion name: PodVersion version: '6.011' - class: Dist::Zilla::Plugin::Test::Kwalitee config: Dist::Zilla::Plugin::Test::Kwalitee: filename: xt/release/kwalitee.t skiptest: [] name: Test::Kwalitee version: '2.12' - class: Dist::Zilla::Plugin::Test::EOL config: Dist::Zilla::Plugin::Test::EOL: filename: xt/author/eol.t finder: - ':InstallModules' trailing_whitespace: 1 name: Test::EOL version: '0.19' - class: Dist::Zilla::Plugin::Test::PAUSE::Permissions name: Test::PAUSE::Permissions version: '0.003' - class: Dist::Zilla::Plugin::GithubMeta name: GithubMeta version: '0.54' - class: Dist::Zilla::Plugin::NextRelease name: NextRelease version: '6.011' - class: Dist::Zilla::Plugin::Git::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: [] exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . Dist::Zilla::Plugin::Git::GatherDir: include_untracked: 0 name: Git::GatherDir version: '2.043' - class: Dist::Zilla::Plugin::Git::NextVersion config: Dist::Zilla::Plugin::Git::NextVersion: first_version: '0.001' version_by_branch: 0 version_regexp: (?^:^v(.+)$) Dist::Zilla::Role::Git::Repo: git_version: 1.9.1 repo_root: . name: Git::NextVersion version: '2.043' - class: Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch config: Dist::Zilla::Role::Git::Repo: git_version: 1.9.1 repo_root: . name: Git::CheckFor::CorrectBranch version: '0.014' - class: Dist::Zilla::Plugin::Git::Remote::Check name: Git::Remote::Check version: 0.1.2 - class: Dist::Zilla::Plugin::PruneCruft name: '@Starter/PruneCruft' version: '6.011' - class: Dist::Zilla::Plugin::ManifestSkip name: '@Starter/ManifestSkip' version: '6.011' - class: Dist::Zilla::Plugin::MetaConfig name: '@Starter/MetaConfig' version: '6.011' - class: Dist::Zilla::Plugin::MetaProvides::Package config: Dist::Zilla::Plugin::MetaProvides::Package: finder_objects: - class: Dist::Zilla::Plugin::FinderCode name: '@Starter/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.011' include_underscores: 0 Dist::Zilla::Role::MetaProvider::Provider: $Dist::Zilla::Role::MetaProvider::Provider::VERSION: '2.002004' inherit_missing: '1' inherit_version: '1' meta_noindex: '1' Dist::Zilla::Role::ModuleMetadata: Module::Metadata: '1.000033' version: '0.005' name: '@Starter/MetaProvides::Package' version: '2.004003' - class: Dist::Zilla::Plugin::MetaNoIndex name: '@Starter/MetaNoIndex' version: '6.011' - class: Dist::Zilla::Plugin::MetaYAML name: '@Starter/MetaYAML' version: '6.011' - class: Dist::Zilla::Plugin::MetaJSON name: '@Starter/MetaJSON' version: '6.011' - class: Dist::Zilla::Plugin::License name: '@Starter/License' version: '6.011' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: '@Starter/ReadmeAnyFromPod' version: '0.163250' - class: Dist::Zilla::Plugin::ExecDir name: '@Starter/ExecDir' version: '6.011' - class: Dist::Zilla::Plugin::ShareDir name: '@Starter/ShareDir' version: '6.011' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@Starter/PodSyntaxTests' version: '6.011' - class: Dist::Zilla::Plugin::Test::ReportPrereqs name: '@Starter/Test::ReportPrereqs' version: '0.027' - class: Dist::Zilla::Plugin::Test::Compile config: Dist::Zilla::Plugin::Test::Compile: bail_out_on_fail: '0' fail_on_warning: author fake_home: 0 filename: xt/author/00-compile.t module_finder: - ':InstallModules' needs_display: 0 phase: develop script_finder: - ':PerlExecFiles' skips: [] switch: [] name: '@Starter/Test::Compile' version: '2.058' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Starter/MakeMaker' version: '6.011' - class: Dist::Zilla::Plugin::Manifest name: '@Starter/Manifest' version: '6.011' - class: Dist::Zilla::Plugin::TestRelease name: '@Starter/TestRelease' version: '6.011' - class: Dist::Zilla::Plugin::RunExtraTests config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Starter/RunExtraTests' version: '0.029' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Starter/ConfirmRelease' version: '6.011' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Starter/UploadToCPAN' version: '6.011' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: Pod_Readme version: '0.163250' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - README.pod - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 1.9.1 repo_root: . name: '@Git/Check' version: '2.043' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: 'v%v%t - %d%n%n%c' Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - README.pod - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 1.9.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Git/Commit' version: '2.043' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: v2.03 tag_format: v%v%t tag_message: 'v%v%t - %d' Dist::Zilla::Role::Git::Repo: git_version: 1.9.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Git/Tag' version: '2.043' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - origin remotes_must_exist: 1 Dist::Zilla::Role::Git::Repo: git_version: 1.9.1 repo_root: . name: '@Git/Push' version: '2.043' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.011' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.011' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.011' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.011' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.011' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.011' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.011' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.011' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.011' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.011' - class: Dist::Zilla::Plugin::FinderCode name: '@Starter/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.011' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '6.011' x_serialization_backend: 'YAML::Tiny version 1.73' HTML-FormFu-Model-DBIC-2.03/README0000644000175100017520000005254713262760616014470 0ustar carlcarlNAME HTML::FormFu::Model::DBIC - Integrate HTML::FormFu with DBIx::Class VERSION version 2.03 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; } SETUP For the form object to be able to access your DBIx::Class schema, it needs to be placed on the form stash, with the name schema. This is easy if you're using Catalyst-Controller-HTML-FormFu, as you can set this up to happen in your Catalyst app's config file. For example, if your model is named MyApp::Model::Corp, you would set this (in Config::General format): schema Corp Or if your app's config file is in YAML format: 'Controller::HTML::FormFu': model_stash: schema: Corp METHODS 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. update Arguments: [$dbic_row], [\%config] Return Value: $dbic_row $form->model->update( $dbic_row ); Update the database with the submitted form values. create Arguments: [\%config] Return Value: $dbic_row my $dbic_row = $form->model->create( {resultset => 'Book'} ); Like "update", but doesn't require a $dbic_row argument. You need to ensure the DBIC schema is available on the form stash - see "SYNOPSIS" for an example config. The resultset must be set either in the method arguments, or the form or block's model_config. An example of setting the ResultSet name on a Form: --- model_config: resultset: FooTable elements: # [snip] 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 $form->process by fields that inherit from HTML::FormFu::Element::_Group. This includes: HTML::FormFu::Element::Select HTML::FormFu::Element::Checkboxgroup HTML::FormFu::Element::Radiogroup HTML::FormFu::Element::ComboBox To use you must set the appropriate resultset on the element model_config: element: - type: Select name: foo model_config: resultset: TableClass BUILDING FORMS 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 might_have and has_one relationships Set field values from a related row with a might_have or has_one relationship by placing the fields within a Block (or any element that inherits from Block, such as Fieldset) with its "nested_name" in HTML::FormFu set to the relationship name. For the following DBIx::Class schemas: 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" }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->might_have( review => 'MySchema::Review', 'book' ); 1; package MySchema::Review; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/ Core /); __PACKAGE__->table("review"); __PACKAGE__->add_columns( id => { data_type => "INTEGER" }, book => { data_type => "INTEGER", is_nullable => 1 }, review_text => { data_type => "TEXT" }, ); __PACKAGE__->set_primary_key("book"); __PACKAGE__->belongs_to( book => 'MySchema::Book' ); 1; A suitable form for this would be: elements: - type: Text name: title - type: Block nested_name: review elements: - type: Textarea name: review_text For might_have and has_one relationships, you generally shouldn't need to have a field for the related table's primary key, as DBIx::Class will handle retrieving the correct row automatically. You can also set a has_one or might_have relationship using a multi value field like Select. elements: - type: Text name: title - type: Select nested: review model_config: resultset: Review This will load all reviews into the select field. If you select a review from that list, a current relationship to a review is removed and the new one is added. This requires that the primary key of the Review table and the foreign key do not match. has_many and many_to_many relationships The general principle is the same as for might_have and has_one above, except you should use a Repeatable element instead of a Block, and it needs to contain a Hidden field corresponding to the primary key of the related table. The Repeatable block's nested_name must be set to the name of the relationship. The Repeable block's increment_field_names must be true (which is the default value). The Repeable block's counter_name must be set to the name of a Hidden field, which is placed outside of the Repeatable block. This field is used to store a count of the number of repetitions of the Repeatable block were created. When the form is submitted, this value is used during $form->process to ensure the form is rebuilt with the correct number of repetitions. To allow the user to add new related rows, either empty_rows or new_rows_max must be set - see "Config options for Repeatable blocks" below. For the following DBIx::Class schemas: 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" }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( review => 'MySchema::Review', 'book' ); 1; package MySchema::Review; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/ Core /); __PACKAGE__->table("review"); __PACKAGE__->add_columns( book => { data_type => "INTEGER" }, review_text => { data_type => "TEXT" }, ); __PACKAGE__->set_primary_key("book"); __PACKAGE__->belongs_to( book => 'MySchema::Book' ); 1; A suitable form for this might be: elements: - type: Text name: title - type: Hidden name: review_count - type: Repeatable nested_name: review counter_name: review_count model_config: empty_rows: 1 elements: - type: Hidden name: book - type: Textarea name: review_text belongs_to relationships Belongs-to relationships can be edited / created with a ComboBox element. If the user selects a value with the Select field, the belongs-to will be set to an already-existing row in the related table. If the user enters a value into the Text field, the belongs-to will be set using a newly-created row in the related table. elements: - type: ComboBox name: author model_config: resultset: Author select_column: id text_column: name The element name should match the relationship name. $field->model_config->{select_column} should match the related primary column. $field->model_config->{text_column} should match the related text column. many_to_many selection To select / deselect rows from a many_to_many relationship, you must use a multi-valued element, such as a Checkboxgroup or a Select with multiple set. The field's name must be set to the name of the many_to_many relationship. default_column If you want to search / associate the related table by a column other it's primary key, set $field->model_config->{default_column}. --- element: - type: Checkboxgroup name: authors model_config: default_column: foo link_values If you want to set columns on the link table you can do so if you add a link_values attribute to model_config: --- element: - type: Checkboxgroup name: authors model_config: link_values: foo: bar additive The default implementation will first remove all related objects and set the new ones (see http://search.cpan.org/perldoc?DBIx::Class::Relationship::Base#set_$rel). If you want to add the selected objects to the current set of objects set additive in the model_config. --- element: - type: Checkboxgroup name: authors model_config: additive: 1 options_from_model: 0 "options_from_model" is set to 0 because it will try to fetch all objects from the result class Authors if model_config is specified without a resultset attribute.) COMMON ARGUMENTS The following items are supported in the optional config hash-ref argument to the methods default_values, update and create. base If you want the method to process a particular Block element, rather than the whole form, you can pass the element as a base argument. $form->default_values( $row, { base => $formfu_element, }, ); nested_base If you want the method to process a particular Block element by name, you can pass the name as an argument. $form->default_values( $row, { nested_base => 'foo', }' ); CONFIGURATION Config options for fields The following items are supported as model_config options on form fields. accessor If set, accessor will be used as a method-name accessor on the DBIx::Class row object, instead of using the field name. ignore_if_empty If the submitted value is blank, no attempt will be made to save it to the database. null_if_empty If the submitted value is blank, save it as NULL to the database. Normally an empty string is saved as NULL when its corresponding field is numeric, and as an empty string when its corresponding field is a text field. This option is useful for changing the default behavior for text fields. delete_if_empty Useful for editing a "might_have" related row containing only one field. If the submitted value is blank, the related row is deleted. For the following DBIx::Class schemas: 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" }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->might_have( review => 'MySchema::Review', 'book' ); 1; package MySchema::Review; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/ Core /); __PACKAGE__->table("review"); __PACKAGE__->add_columns( book => { data_type => "INTEGER" }, review_text => { data_type => "TEXT" }, ); __PACKAGE__->set_primary_key("book"); __PACKAGE__->belongs_to( book => 'MySchema::Book' ); 1; A suitable form for this would be: elements: - type: Text name: title - type: Block nested_name: review elements: - type: Text name: review_text model_config: delete_if_empty: 1 label To use a column value for a form field's label. Config options for fields within a Repeatable block delete_if_true Intended for use on a Checkbox field. If the checkbox is checked, the following occurs: for a has-many relationship, the related row is deleted; for a many-to-many relationship, the relationship link is removed. An example of use might be: elements: - type: Text name: title - type: Hidden name: review_count - type: Repeatable nested_name: review counter_name: review_count elements: - type: Hidden name: book - type: Textarea name: review_text - type: Checkbox name: delete_review label: 'Delete Review?' model_config: delete_if_true: 1 Note: make sure the name of this field does not clash with one of your DBIx::Class::Row method names (e.g. "delete") - see "CAVEATS". Config options for Repeatable blocks empty_rows For a Repeatable block corresponding to a has-many or many-to-many relationship, to allow the user to insert new rows, set empty_rows to the number of extra repetitions you wish added to the end of the Repeatable block. new_rows_max Set to the maximum number of new rows that a Repeatable block is allowed to add. If not set, it will fallback to the value of empty_rows. Config options for options_from_model The column used for the element values is set with the model_config value id_column - or if not set, the table's primary column is used. element: - type: Select name: foo model_config: resultset: TableClass id_column: pk_col The column used for the element labels is set with the model_config value label_column - or if not set, the first text/varchar column found in the table is used - or if one is not found, the id_column is used instead. element: - type: Select name: foo model_config: resultset: TableClass label_column: label_col To pass the database label values via the form's localization object, set localize_label element: - type: Select name: foo model_config: localize_label: 1 You can set a condition, which will be passed as the 1st argument to "search" in DBIx::Class::ResultSet. element: - type: Select name: foo model_config: resultset: TableClass condition: type: is_foo You can set a condition_from_stash, which will be passed as the 1st argument to "search" in DBIx::Class::ResultSet. key is the column-name to be passed to search, and stash_key is the name of a key on the form stash from which the value to be passed to search is found. element: - type: Select name: foo model_config: resultset: TableClass condition_from_stash: key: stash_key Is comparable to: $form->element({ type => 'Select', name => 'foo', model_config => { resultset => 'TableClass', condition => { key => $form->stash->{stash_key} } } }) If the value in the stash is nested in a data-structure, you can access it by setting expand_stash_dots. As you can see in the example below, it automatically handles calling methods on objects, accessing hash-keys on hash-references, and accessing array-slots on array references. element: - type: Select name: foo model_config: resultset: TableClass condition_from_stash: key: foo.bar.0 expand_stash_dots: 1 Is comparable to: $form->element({ type => 'Select', name => 'foo', model_config => { resultset => 'TableClass', condition => { key => $form->stash->{foo}->bar->[0]; } } }) # Where stash returns a hashref. # The 'foo' hash-key returns an object. # The object-method 'bar' returns an arrayref. # The first array slot returns the value used in the query. You can set attributes, which will be passed as the 2nd argument to "search" in DBIx::Class::ResultSet. ENUM Column Type If the field name matches (case-insensitive) a column name with type 'ENUM' and the Schema contains enum values in $resultset->column_info($name)->{extra}{list}, the field's options will be populated with the enum values. FAQ Add extra values not in the form To update values to the database which weren't submitted to the form, you can first add them to the form with add_valid. my $passwd = generate_passwd(); $form->add_valid( passwd => $passwd ); $form->model->update( $row ); add_valid works for fieldnames that don't exist in the form. Set a field read only You can make a field read only. The value of such fields cannot be changed by the user even if they submit a value for it. $field->model_config->{read_only} = 1; - Name: field model_config: read_only: 1 See HTML::FormFu::Element::Label. CAVEATS To ensure your column's inflators and deflators are called, we have to get / set values using their named methods, and not with get_column / set_column. Because of this, beware of having column names which clash with DBIx::Class built-in method-names, such as delete. - It will have obviously undesirable results! REMOVED METHODS new_empty_row See empty_rows in "Config options for Repeatable blocks" instead. new_empty_row_multi See new_rows_max in "Config options for Repeatable blocks" instead. Range constraint See empty_rows in "Config options for Repeatable blocks" instead. SUPPORT Project Page: http://code.google.com/p/html-formfu/ Mailing list: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu Mailing list archives: http://lists.scsys.co.uk/pipermail/html-formfu/ BUGS Please submit bugs / feature requests to http://code.google.com/p/html-formfu/issues/list (preferred) or http://rt.perl.org. GITHUB REPOSITORY This module's sourcecode is maintained in a git repository at git://github.com/fireartist/HTML-FormFu-Model-DBIC.git The project page is https://github.com/fireartist/HTML-FormFu-Model-DBIC SEE ALSO HTML::FormFu, DBIx::Class, Catalyst::Controller::HTML::FormFu AUTHOR Carl Franks CONTRIBUTORS Based on the code of DBIx::Class::HTML::FormFu, which was contributed to by: Adam Herzog Daisuke Maki Mario Minati COPYRIGHT AND LICENSE Copyright (C) 2007 by Carl Franks Based on the original source code of DBIx::Class::HTMLWidget, copyright Thomas Klausner. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. HTML-FormFu-Model-DBIC-2.03/Makefile.PL0000644000175100017520000000346313262760616015553 0ustar carlcarl# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.011. use strict; use warnings; use 5.008001; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Integrate HTML::FormFu with DBIx::Class", "AUTHOR" => "Carl Franks ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "HTML-FormFu-Model-DBIC", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.008001", "NAME" => "HTML::FormFu::Model::DBIC", "PREREQ_PM" => { "DBD::SQLite" => 0, "DBIx::Class" => "0.08108", "HTML::FormFu" => "2.00", "List::MoreUtils" => 0, "MooseX::Attribute::Chained" => "1.0.2", "Storable" => 0, "Task::Weaken" => 0 }, "TEST_REQUIRES" => { "DateTime::Format::SQLite" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Locale::Maketext" => 0, "SQL::Translator" => "0.11016", "Test::More" => "0.99" }, "VERSION" => "2.03", "test" => { "TESTS" => "t/*.t t/constraints/*.t t/create/*.t t/default_values/*.t t/options_from_model/*.t t/update/*.t t/x_roundtrip/*.t" } ); my %FallbackPrereqs = ( "DBD::SQLite" => 0, "DBIx::Class" => "0.08108", "DateTime::Format::SQLite" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "HTML::FormFu" => "2.00", "List::MoreUtils" => 0, "Locale::Maketext" => 0, "MooseX::Attribute::Chained" => "1.0.2", "SQL::Translator" => "0.11016", "Storable" => 0, "Task::Weaken" => 0, "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); HTML-FormFu-Model-DBIC-2.03/META.json0000644000175100017520000004227013262760616015221 0ustar carlcarl{ "abstract" : "Integrate HTML::FormFu with DBIx::Class", "author" : [ "Carl Franks " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.011, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "HTML-FormFu-Model-DBIC", "no_index" : { "directory" : [ "eg", "examples", "inc", "share", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::CPAN::Meta" : "0", "Test::EOL" : "0", "Test::Kwalitee" : "1.21", "Test::More" : "0.88", "Test::PAUSE::Permissions" : "0", "Test::Perl::Critic" : "0", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "DBD::SQLite" : "0", "DBIx::Class" : "0.08108", "HTML::FormFu" : "2.00", "List::MoreUtils" : "0", "MooseX::Attribute::Chained" : "v1.0.2", "Storable" : "0", "Task::Weaken" : "0", "perl" : "5.008001" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "DateTime::Format::SQLite" : "0", "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "Locale::Maketext" : "0", "SQL::Translator" : "0.11016", "Test::More" : "0.99" } } }, "provides" : { "HTML::FormFu::Constraint::DBIC::Unique" : { "file" : "lib/HTML/FormFu/Constraint/DBIC/Unique.pm", "version" : "2.03" }, "HTML::FormFu::Model::DBIC" : { "file" : "lib/HTML/FormFu/Model/DBIC.pm", "version" : "2.03" } }, "release_status" : "stable", "resources" : { "homepage" : "https://github.com/FormFu/HTML-FormFu-Model-DBIC", "repository" : { "type" : "git", "url" : "https://github.com/FormFu/HTML-FormFu-Model-DBIC.git", "web" : "https://github.com/FormFu/HTML-FormFu-Model-DBIC" } }, "version" : "2.03", "x_Dist_Zilla" : { "perl" : { "version" : "5.014004" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "runtime", "type" : "requires" } }, "name" : "Prereqs", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "TestRequires", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "develop", "type" : "requires" } }, "name" : "DevelopRequires", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::Test::Perl::Critic", "name" : "Test::Perl::Critic", "version" : "3.001" }, { "class" : "Dist::Zilla::Plugin::MetaTests", "name" : "MetaTests", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::OurPkgVersion", "name" : "OurPkgVersion", "version" : "0.12" }, { "class" : "Dist::Zilla::Plugin::PodVersion", "name" : "PodVersion", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::Test::Kwalitee", "config" : { "Dist::Zilla::Plugin::Test::Kwalitee" : { "filename" : "xt/release/kwalitee.t", "skiptest" : [] } }, "name" : "Test::Kwalitee", "version" : "2.12" }, { "class" : "Dist::Zilla::Plugin::Test::EOL", "config" : { "Dist::Zilla::Plugin::Test::EOL" : { "filename" : "xt/author/eol.t", "finder" : [ ":InstallModules" ], "trailing_whitespace" : 1 } }, "name" : "Test::EOL", "version" : "0.19" }, { "class" : "Dist::Zilla::Plugin::Test::PAUSE::Permissions", "name" : "Test::PAUSE::Permissions", "version" : "0.003" }, { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "GithubMeta", "version" : "0.54" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "NextRelease", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." }, "Dist::Zilla::Plugin::Git::GatherDir" : { "include_untracked" : 0 } }, "name" : "Git::GatherDir", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::Git::NextVersion", "config" : { "Dist::Zilla::Plugin::Git::NextVersion" : { "first_version" : "0.001", "version_by_branch" : 0, "version_regexp" : "(?^:^v(.+)$)" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "1.9.1", "repo_root" : "." } }, "name" : "Git::NextVersion", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch", "config" : { "Dist::Zilla::Role::Git::Repo" : { "git_version" : "1.9.1", "repo_root" : "." } }, "name" : "Git::CheckFor::CorrectBranch", "version" : "0.014" }, { "class" : "Dist::Zilla::Plugin::Git::Remote::Check", "name" : "Git::Remote::Check", "version" : "0.1.2" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Starter/PruneCruft", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Starter/ManifestSkip", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@Starter/MetaConfig", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::MetaProvides::Package", "config" : { "Dist::Zilla::Plugin::MetaProvides::Package" : { "finder_objects" : [ { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@Starter/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.011" } ], "include_underscores" : 0 }, "Dist::Zilla::Role::MetaProvider::Provider" : { "$Dist::Zilla::Role::MetaProvider::Provider::VERSION" : "2.002004", "inherit_missing" : 1, "inherit_version" : 1, "meta_noindex" : 1 }, "Dist::Zilla::Role::ModuleMetadata" : { "Module::Metadata" : "1.000033", "version" : "0.005" } }, "name" : "@Starter/MetaProvides::Package", "version" : "2.004003" }, { "class" : "Dist::Zilla::Plugin::MetaNoIndex", "name" : "@Starter/MetaNoIndex", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Starter/MetaYAML", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@Starter/MetaJSON", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Starter/License", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "@Starter/ReadmeAnyFromPod", "version" : "0.163250" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Starter/ExecDir", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Starter/ShareDir", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@Starter/PodSyntaxTests", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::Test::ReportPrereqs", "name" : "@Starter/Test::ReportPrereqs", "version" : "0.027" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "config" : { "Dist::Zilla::Plugin::Test::Compile" : { "bail_out_on_fail" : 0, "fail_on_warning" : "author", "fake_home" : 0, "filename" : "xt/author/00-compile.t", "module_finder" : [ ":InstallModules" ], "needs_display" : 0, "phase" : "develop", "script_finder" : [ ":PerlExecFiles" ], "skips" : [], "switch" : [] } }, "name" : "@Starter/Test::Compile", "version" : "2.058" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Starter/MakeMaker", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Starter/Manifest", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@Starter/TestRelease", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::RunExtraTests", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Starter/RunExtraTests", "version" : "0.029" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Starter/ConfirmRelease", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Starter/UploadToCPAN", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "Pod_Readme", "version" : "0.163250" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "README.pod", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "1.9.1", "repo_root" : "." } }, "name" : "@Git/Check", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "v%v%t - %d%n%n%c" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "README.pod", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "1.9.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Git/Commit", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "v2.03", "tag_format" : "v%v%t", "tag_message" : "v%v%t - %d" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "1.9.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Git/Tag", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin" ], "remotes_must_exist" : 1 }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "1.9.1", "repo_root" : "." } }, "name" : "@Git/Push", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.011" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@Starter/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.011" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.011" } }, "x_serialization_backend" : "Cpanel::JSON::XS version 4.02" } HTML-FormFu-Model-DBIC-2.03/lib/0000775000175100017520000000000013262760616014343 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/lib/HTML/0000775000175100017520000000000013262760616015107 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/0000775000175100017520000000000013262760616016305 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/Constraint/0000775000175100017520000000000013262760616020431 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/Constraint/DBIC/0000775000175100017520000000000013262760616021132 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/Constraint/DBIC/Unique.pm0000644000175100017520000001674113262760616022745 0ustar carlcarlpackage HTML::FormFu::Constraint::DBIC::Unique; use strict; our $VERSION = '2.03'; # VERSION use Moose; use MooseX::Attribute::Chained; extends 'HTML::FormFu::Constraint'; use Carp qw( carp croak ); use HTML::FormFu::Util qw( DEBUG_CONSTRAINTS debug ); has model => ( is => 'rw', traits => ['Chained'] ); has resultset => ( is => 'rw', traits => ['Chained'] ); has column => ( is => 'rw', traits => ['Chained'] ); has method_name => ( is => 'rw', traits => ['Chained'] ); has self_stash_key => ( is => 'rw', traits => ['Chained'] ); has others => ( is => 'rw', traits => ['Chained'] ); has id_field => ( is => 'rw', traits => ['Chained'] ); sub constrain_value { my ( $self, $value ) = @_; return 1 if !defined $value || $value eq ''; for (qw/ resultset /) { if ( !defined $self->$_ ) { # warn and die, as errors are swallowed by HTML-FormFu carp "'$_' is not defined"; croak "'$_' is not defined"; } } # get stash my $stash = $self->form->stash; my $schema; if ( defined $stash->{schema} ) { $schema = $stash->{schema}; } elsif ( defined $stash->{context} && defined $self->model ) { $schema = $stash->{context}->model( $self->model ); } elsif ( defined $stash->{context} ) { $schema = $stash->{context}->model; } if ( !defined $schema ) { # warn and die, as errors are swallowed by HTML-FormFu carp 'could not find DBIC schema'; croak 'could not find DBIC schema'; } my $resultset = $schema->resultset( $self->resultset ); if ( !defined $resultset ) { # warn and die, as errors are swallowed by HTML-FormFu carp 'could not find DBIC resultset'; croak 'could not find DBIC resultset'; } if ( my $method_name = $self->method_name ) { # warn "using $method_name to look for $value"; # need to be able to tell $method_name about record on the form stash my $pk_val; if ( defined( my $self_stash_key = $self->self_stash_key ) ) { if ( defined( my $self_stash = $stash->{ $self_stash_key } ) ) { my ($pk) = $resultset->result_source->primary_columns; $pk_val = $self_stash->$pk; } } return $resultset->$method_name( $value, $pk_val ); } else { my $column = $self->column || $self->parent->name; my %others; if ( $self->others ) { my @others = ref $self->others ? @{ $self->others } : $self->others; my $params = $self->form->input; %others = grep { defined && length } map { $_ => $self->get_nested_hash_value( $params, $_ ) } @others; } my $existing_row = eval { $resultset->find( { %others, $column => $value } ); }; if ( my $error = $@ ) { # warn and die, as errors are swallowed by HTML-FormFu carp $error; croak $error; } # if a row exists, first check whether it matches a known object on the # form stash if ( $existing_row && defined( my $self_stash_key = $self->self_stash_key ) ) { if ( defined( my $self_stash = $stash->{ $self_stash_key } ) ) { my ($pk) = $resultset->result_source->primary_columns; if ( $existing_row->$pk eq $self_stash->$pk ) { return 1; } } } elsif ( $existing_row && defined (my $id_field = $self->id_field ) ) { my $value = $self->get_nested_hash_value( $self->form->input, $id_field ); if ( defined $value && length $value ) { my ($pk) = $resultset->result_source->primary_columns; return ($existing_row->$pk eq $value); } } return !$existing_row; } } after repeatable_repeat => sub { my ( $self, $repeatable, $new_block ) = @_; # rename any 'id_field' fields if ( my $id_field = $self->id_field ) { my $block_fields = $new_block->get_fields; my $field = $repeatable->get_field_with_original_name( $id_field, $block_fields ); if ( defined $field ) { DEBUG_CONSTRAINTS && debug( sprintf "Repeatable renaming constraint 'id_field' '%s' to '%s'", $id_field, $field->nested_name, ); $self->id_field( $field->nested_name ); } } }; 1; __END__ =head1 NAME HTML::FormFu::Constraint::DBIC::Unique - unique constraint for HTML::FormFu::Model::DBIC =head1 VERSION version 2.03 =head1 SYNOPSIS $form->stash->{schema} = $dbic_schema; # DBIC schema $form->element('text') ->name('email') ->constraint('DBIC::Unique') ->resultset('User') ; $form->stash->{context} = $c; # Catalyst context $form->element('text') ->name('email') ->constraint('DBIC::Unique') ->model('DBIC::User') ; $form->element('text') ->name('user') ->constraint('DBIC::Unique') ->model('DBIC') ->resultset('User') ; or in a config file: --- elements: - type: text name: email constraints: - Required - type: DBIC::Unique model: DBIC::User - type: text name: user constraints: - Required - type: DBIC::Unique model: DBIC::User column: username =head1 DESCRIPTION Checks if the input value exists in a DBIC ResultSet. =head1 METHODS =head2 model Arguments: $string # a Catalyst model name like 'DBIC::User' =head2 resultset Arguments: $string # a DBIC resultset name like 'User' =head2 self_stash_key reference to a key in the form stash. if this key exists, the constraint will check if the id matches the one of this element, so that you can use your own name. =head2 id_field Use this key to define reference field which consist of primary key of resultset. If the field exists (and $self_stash_key not defined), the constraint will check if the id matches the primary key of row object: --- elements: - type: Hidden name: id constraints: - Required - type: Text name: value label: Value constraints: - Required - type: DBIC::Unique resultset: ControlledVocab id_field: id =head2 others Use this key to manage unique compound database keys which consist of more than one column. For example, if a database key consists of 'category' and 'value', use a config file such as this: --- elements: - type: Text name: category label: Category constraints: - Required - type: Text name: value label: Value constraints: - Required - type: DBIC::Unique resultset: ControlledVocab others: category =head2 method_name Name of a method which will be called on the resultset. The method is passed two argument; the value of the field, and the primary key value (usually `id`) of the record in the form stash (as defined by self_stash_key). An example config might be: --- elements: - type: text name: user constraints: - Required - type: DBIC::Unique model: DBIC::User method_name: is_username_available =head2 SEE ALSO Is a sub-class of, and inherits methods from L L =head1 AUTHOR Jonas Alves C =head1 LICENSE This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. HTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/Model/0000775000175100017520000000000013262760616017345 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/Model/DBIC.pm0000644000175100017520000015373213262760616020415 0ustar carlcarlpackage HTML::FormFu::Model::DBIC; use strict; use warnings; use base 'HTML::FormFu::Model'; our $VERSION = '2.03'; # VERSION use HTML::FormFu::Util qw( _merge_hashes ); use List::MoreUtils qw( none notall ); use List::Util qw( first ); use Scalar::Util qw( blessed reftype ); 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}; if ( $attrs->{expand_stash_dots} ) { $condition->{$name} = $self->_get_stash_value( $form->stash, $from_stash->{$name} ); } else { $condition->{$name} = $form->stash->{ $from_stash->{$name} }; } } } # 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_stash_value { my ( $self, $stash, $key ) = @_; my $base = $stash; if ( $key =~ /\./ ) { for my $part ( grep {length} split qr/\./, $key ) { if ( blessed($base) && $base->can($part) ) { $base = $base->$part; } elsif ( 'HASH' eq reftype($base) ) { $base = $base->{$part}; } elsif ( 'ARRAY' eq reftype($base) && $key =~ /^[0-9]+\z/ ) { $base = $base->[$key]; } else { croak "don't know what to do with part '$part' in key '$key'"; } } } return $base; } 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) and !$dbic->can( 'add_to_' . $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 VERSION version 2.03 =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) with its L set to the relationship name. For the following DBIx::Class schemas: 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" }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->might_have( review => 'MySchema::Review', 'book' ); 1; package MySchema::Review; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/ Core /); __PACKAGE__->table("review"); __PACKAGE__->add_columns( id => { data_type => "INTEGER" }, book => { data_type => "INTEGER", is_nullable => 1 }, review_text => { data_type => "TEXT" }, ); __PACKAGE__->set_primary_key("book"); __PACKAGE__->belongs_to( book => 'MySchema::Book' ); 1; A suitable form for this would be: elements: - type: Text name: title - type: Block nested_name: review elements: - type: Textarea name: review_text For C and C relationships, you generally shouldn't need to have a field for the related table's primary key, as DBIx::Class will handle retrieving the correct row automatically. You can also set a C or C relationship using a multi value field like L. elements: - type: Text name: title - type: Select nested: review model_config: resultset: Review This will load all reviews into the select field. If you select a review from that list, a current relationship to a review is removed and the new one is added. This requires that the primary key of the C table and the foreign key do not match. =head2 has_many and many_to_many relationships The general principle is the same as for C and C above, except you should use a L element instead of a Block, and it needs to contain a L field corresponding to the primary key of the related table. The Repeatable block's L must be set to the name of the relationship. The Repeable block's L must be true (which is the default value). The Repeable block's L must be set to the name of a L field, which is placed outside of the Repeatable block. This field is used to store a count of the number of repetitions of the Repeatable block were created. When the form is submitted, this value is used during C<< $form->process >> to ensure the form is rebuilt with the correct number of repetitions. To allow the user to add new related rows, either C or C must be set - see L below. For the following DBIx::Class schemas: 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" }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( review => 'MySchema::Review', 'book' ); 1; package MySchema::Review; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/ Core /); __PACKAGE__->table("review"); __PACKAGE__->add_columns( book => { data_type => "INTEGER" }, review_text => { data_type => "TEXT" }, ); __PACKAGE__->set_primary_key("book"); __PACKAGE__->belongs_to( book => 'MySchema::Book' ); 1; A suitable form for this might be: elements: - type: Text name: title - type: Hidden name: review_count - type: Repeatable nested_name: review counter_name: review_count model_config: empty_rows: 1 elements: - type: Hidden name: book - type: Textarea name: review_text =head2 belongs_to relationships Belongs-to relationships can be edited / created with a ComboBox element. If the user selects a value with the Select field, the belongs-to will be set to an already-existing row in the related table. If the user enters a value into the Text field, the belongs-to will be set using a newly-created row in the related table. elements: - type: ComboBox name: author model_config: resultset: Author select_column: id text_column: name The element name should match the relationship name. C<< $field->model_config->{select_column} >> should match the related primary column. C<< $field->model_config->{text_column} >> should match the related text column. =head2 many_to_many selection To select / deselect rows from a C relationship, you must use a multi-valued element, such as a L or a L with L set. The field's L must be set to the name of the C relationship. =head3 default_column If you want to search / associate the related table by a column other it's primary key, set C<< $field->model_config->{default_column} >>. --- element: - type: Checkboxgroup name: authors model_config: default_column: foo =head3 link_values If you want to set columns on the link table you can do so if you add a C attribute to C: --- element: - type: Checkboxgroup name: authors model_config: link_values: foo: bar =head3 additive The default implementation will first remove all related objects and set the new ones (see L). If you want to add the selected objects to the current set of objects set C in the C. --- element: - type: Checkboxgroup name: authors model_config: additive: 1 options_from_model: 0 L is set to C<0> because it will try to fetch all objects from the result class C if C is specified without a C attribute.) =head1 COMMON ARGUMENTS The following items are supported in the optional C hash-ref argument to the methods L, L and L. =over =item base If you want the method to process a particular Block element, rather than the whole form, you can pass the element as a C argument. $form->default_values( $row, { base => $formfu_element, }, ); =item nested_base If you want the method to process a particular Block element by L, you can pass the name as an argument. $form->default_values( $row, { nested_base => 'foo', }' ); =back =head1 CONFIGURATION =head2 Config options for fields The following items are supported as C options on form fields. =over =item accessor If set, C will be used as a method-name accessor on the C row object, instead of using the field name. =item ignore_if_empty If the submitted value is blank, no attempt will be made to save it to the database. =item null_if_empty If the submitted value is blank, save it as NULL to the database. Normally an empty string is saved as NULL when its corresponding field is numeric, and as an empty string when its corresponding field is a text field. This option is useful for changing the default behavior for text fields. =item delete_if_empty Useful for editing a "might_have" related row containing only one field. If the submitted value is blank, the related row is deleted. For the following DBIx::Class schemas: 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" }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->might_have( review => 'MySchema::Review', 'book' ); 1; package MySchema::Review; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/ Core /); __PACKAGE__->table("review"); __PACKAGE__->add_columns( book => { data_type => "INTEGER" }, review_text => { data_type => "TEXT" }, ); __PACKAGE__->set_primary_key("book"); __PACKAGE__->belongs_to( book => 'MySchema::Book' ); 1; A suitable form for this would be: elements: - type: Text name: title - type: Block nested_name: review elements: - type: Text name: review_text model_config: delete_if_empty: 1 =item label To use a column value for a form field's L. =back =head2 Config options for fields within a Repeatable block =over =item delete_if_true Intended for use on a L field. If the checkbox is checked, the following occurs: for a has-many relationship, the related row is deleted; for a many-to-many relationship, the relationship link is removed. An example of use might be: elements: - type: Text name: title - type: Hidden name: review_count - type: Repeatable nested_name: review counter_name: review_count elements: - type: Hidden name: book - type: Textarea name: review_text - type: Checkbox name: delete_review label: 'Delete Review?' model_config: delete_if_true: 1 Note: make sure the name of this field does not clash with one of your L method names (e.g. "delete") - see L. =back =head2 Config options for Repeatable blocks =over =item empty_rows For a Repeatable block corresponding to a has-many or many-to-many relationship, to allow the user to insert new rows, set C to the number of extra repetitions you wish added to the end of the Repeatable block. =item new_rows_max Set to the maximum number of new rows that a Repeatable block is allowed to add. If not set, it will fallback to the value of C. =back =head2 Config options for options_from_model The column used for the element values is set with the C value C - or if not set, the table's primary column is used. element: - type: Select name: foo model_config: resultset: TableClass id_column: pk_col The column used for the element labels is set with the C value C - or if not set, the first text/varchar column found in the table is used - or if one is not found, the C is used instead. element: - type: Select name: foo model_config: resultset: TableClass label_column: label_col To pass the database label values via the form's localization object, set C element: - type: Select name: foo model_config: localize_label: 1 You can set a C, which will be passed as the 1st argument to L. element: - type: Select name: foo model_config: resultset: TableClass condition: type: is_foo You can set a C, which will be passed as the 1st argument to L. C is the column-name to be passed to L, and C is the name of a key on the form L from which the value to be passed to L is found. element: - type: Select name: foo model_config: resultset: TableClass condition_from_stash: key: stash_key Is comparable to: $form->element({ type => 'Select', name => 'foo', model_config => { resultset => 'TableClass', condition => { key => $form->stash->{stash_key} } } }) If the value in the stash is nested in a data-structure, you can access it by setting C. As you can see in the example below, it automatically handles calling methods on objects, accessing hash-keys on hash-references, and accessing array-slots on array references. element: - type: Select name: foo model_config: resultset: TableClass condition_from_stash: key: foo.bar.0 expand_stash_dots: 1 Is comparable to: $form->element({ type => 'Select', name => 'foo', model_config => { resultset => 'TableClass', condition => { key => $form->stash->{foo}->bar->[0]; } } }) # Where stash returns a hashref. # The 'foo' hash-key returns an object. # The object-method 'bar' returns an arrayref. # The first array slot returns the value used in the query. You can set C, which will be passed as the 2nd argument to L. =head3 ENUM Column Type If the field name matches (case-insensitive) a column name with type 'ENUM' and the Schema contains enum values in C<< $resultset->column_info($name)->{extra}{list} >>, the field's options will be populated with the enum values. =head1 FAQ =head2 Add extra values not in the form To update values to the database which weren't submitted to the form, you can first add them to the form with L. my $passwd = generate_passwd(); $form->add_valid( passwd => $passwd ); $form->model->update( $row ); C works for fieldnames that don't exist in the form. =head2 Set a field read only You can make a field read only. The value of such fields cannot be changed by the user even if they submit a value for it. $field->model_config->{read_only} = 1; - Name: field model_config: read_only: 1 See L. =head1 CAVEATS To ensure your column's inflators and deflators are called, we have to get / set values using their named methods, and not with C / C. Because of this, beware of having column names which clash with DBIx::Class built-in method-names, such as C. - It will have obviously undesirable results! =head1 REMOVED METHODS =head2 new_empty_row See C in L instead. =head2 new_empty_row_multi See C in L instead. =head2 Range constraint See C in L instead. =head1 SUPPORT Project Page: L Mailing list: L Mailing list archives: L =head1 BUGS Please submit bugs / feature requests to L (preferred) or L. =head1 GITHUB REPOSITORY This module's sourcecode is maintained in a git repository at L The project page is L =head1 SEE ALSO L, L, L =head1 AUTHOR Carl Franks =head1 CONTRIBUTORS Based on the code of C, which was contributed to by: Adam Herzog Daisuke Maki Mario Minati =head1 COPYRIGHT AND LICENSE Copyright (C) 2007 by Carl Franks Based on the original source code of L, copyright Thomas Klausner. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. =cut HTML-FormFu-Model-DBIC-2.03/xt/0000775000175100017520000000000013262760616014230 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/xt/release/0000775000175100017520000000000013262760616015650 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/xt/release/distmeta.t0000644000175100017520000000017213262760616017645 0ustar carlcarl#!perl # This file was automatically generated by Dist::Zilla::Plugin::MetaTests. use Test::CPAN::Meta; meta_yaml_ok(); HTML-FormFu-Model-DBIC-2.03/xt/release/kwalitee.t0000644000175100017520000000027513262760616017644 0ustar carlcarl# this test was generated with Dist::Zilla::Plugin::Test::Kwalitee 2.12 use strict; use warnings; use Test::More 0.88; use Test::Kwalitee 1.21 'kwalitee_ok'; kwalitee_ok(); done_testing; HTML-FormFu-Model-DBIC-2.03/xt/release/pause-permissions.t0000644000175100017520000000045413262760616021524 0ustar carlcarluse strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::PAUSE::Permissions 0.003 use Test::More; BEGIN { plan skip_all => 'Test::PAUSE::Permissions required for testing pause permissions' if $] < 5.010; } use Test::PAUSE::Permissions; all_permissions_ok(); HTML-FormFu-Model-DBIC-2.03/xt/author/0000775000175100017520000000000013262760616015532 5ustar carlcarlHTML-FormFu-Model-DBIC-2.03/xt/author/00-compile.t0000644000175100017520000000263313262760616017566 0ustar carlcarluse 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058 use Test::More; plan tests => 3; my @module_files = ( 'HTML/FormFu/Constraint/DBIC/Unique.pm', 'HTML/FormFu/Model/DBIC.pm' ); # no fake home requested my @switches = ( -d 'blib' ? '-Mblib' : '-Ilib', ); use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} } $^X, @switches, '-e', "require q[$lib]")) if $ENV{PERL_COMPILE_TEST_DEBUG}; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { +require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ); HTML-FormFu-Model-DBIC-2.03/xt/author/eol.t0000644000175100017520000000046713262760616016503 0ustar carlcarluse strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::EOL 0.19 use Test::More 0.88; use Test::EOL; my @files = ( 'lib/HTML/FormFu/Constraint/DBIC/Unique.pm', 'lib/HTML/FormFu/Model/DBIC.pm' ); eol_unix_ok($_, { trailing_whitespace => 1 }) foreach @files; done_testing; HTML-FormFu-Model-DBIC-2.03/xt/author/critic.t0000644000175100017520000000020113262760616017163 0ustar carlcarl#!perl use strict; use warnings; use Test::Perl::Critic (-profile => "perlcritic.rc") x!! -e "perlcritic.rc"; all_critic_ok(); HTML-FormFu-Model-DBIC-2.03/xt/author/pod-syntax.t0000644000175100017520000000025213262760616020022 0ustar carlcarl#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); HTML-FormFu-Model-DBIC-2.03/LICENSE0000644000175100017520000004365213262760616014612 0ustar carlcarlThis software is copyright (c) 2016 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) 2016 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, Fifth Floor, Boston, MA 02110-1301 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) 2016 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