File: memory_cycles.t

package info (click to toggle)
libhtml-formhandler-perl 0.40068-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 2,476 kB
  • sloc: perl: 9,416; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,526 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use strict;
use warnings;
use Test::More;
use Test::Memory::Cycle;

{
   package My::RepeatableForm;
   use HTML::FormHandler::Moose;
   extends 'HTML::FormHandler';

   has '+name' => ( default => 'testform' );
   has_field 'reqname' => ( required => 1 );
   has_field 'vegetables' => ( type => 'Multiple' );
   sub options_vegetables {
       return (
           1   => 'lettuce',
           2   => 'broccoli',
           3   => 'carrots',
           4   => 'peas',
       );
   }
   has_field 'entries' => (
        type             => 'Repeatable',
        required         => 1,
        required_message => 'Request without entries not accepted'
    );
    has_field 'entries.rule_index' => ( type => 'PrimaryKey' );
    has_field 'entries.foo' => (
        type     => 'Text',
        required => 1,
    );
    has_field 'entries.bar' => (
        type     => 'Text',
        required => 1,
    );
    has_field 'some_select' => ( type => 'Select', inactive => 1 );

    sub update_model {
        my $self = shift;
        my $value = $self->field('some_select')->value;
    }
}

my $form = new_ok( 'My::RepeatableForm' );

my $params = {
    reqname => 'Testrequest',
    'entries.1.foo' => 'test1',
    'entries.1.bar' => 'test1',
    'entries.2.foo' => 'test2',
    'entries.2.bar' => 'test2',
};
memory_cycle_ok( $form, 'form has no memory cycles before process' );
ok( $form->process( params => $params ), 'form processed ok' );
memory_cycle_ok( $form, 'form has no memory cycles after process' );

done_testing;