CGI-FormMagick

 view release on metacpan or  search on metacpan

lib/CGI/FormMagick/Setup.pm  view on Meta::CPAN

=head2 default_xml_filename()

default source filename to the same as the perl script, with .xml 
extension

=begin testing

BEGIN: {
    use vars qw( $fm );
    use lib "./lib";
    use CGI::FormMagick;
}

ok($fm = CGI::FormMagick->new(type => 'file', source => "t/simple.xml"), "create fm object");
ok($fm2 = CGI::FormMagick->new(type => 'file', source => "t/simple.xml",
	charset => 'ISO-8859-1'), "create fm object with charset");
$fm->parse_xml(); # suck in structure without display()ing
$fm2->parse_xml(); # suck in structure without display()ing

=end testing

=cut

sub default_xml_filename {
    
      my($scriptname, $scriptdir, $extension) =
         File::Basename::fileparse($0, '\.[^\.]+');
    
      return $scriptname . '.xml';
}

=head2 parse_xml()

Parses the XML input, setting $fm->{xml} to a usable hash of the form
elements, and $fm->{lexicon} to a hash of the l10n lexicon.

The $fm->{xml} hash has the following form:

    {
        'form' => {
            'post-event' => 'submit_order',
            'title' => 'FormMagick demo application'
        },
        'pages' => [
            {
                 'post-event' => 'lookup_group_info',
                 'fields' => [
                     {
                         'type' => 'text',
                         'id' => 'firstname',
                         'validation' => 'nonblank',
                         'label' => 'first name'
                     },
                     {
                         'type' => 'text',
                         'id' => 'lastname',
                         'validation' => 'nonblank',
                         'label' => 'last name'
                     }
                     {
                         'type' => 'fragment',
                         'content' => 'This is a simple fragment'
                     }
                     {
                         'type' => 'subroutine',
                         'src' => 'fragment_subroutine_name()'
                     }
                 ],
                 'name' => 'Personal',
                 'title' => 'Personal details'
            }
        ]
    };

Note on lexicon files:
If FormMagick was given a charset argument, then the output will be encoded
in that character set. Otherwise, it will be in UTF-8.

=for testing
is(ref($fm->{xml}), "HASH", "parse_xml gives us a hash");
is($fm->{xml}->{title}, "FormMagick demo application", 
    "Picked up form title");
is(ref($fm->{xml}->{pages}), "ARRAY", 
    "parse_xml gives us an array of pages");
is(ref($fm->{xml}->{pages}->[0]), "HASH", 
    "each page is a hashref");
is($fm->{xml}->{pages}->[0]->{name}, "Personal", 
    "Picked up first page's name");
is($fm->{xml}->{pages}->[0]->{title}, "Personal details", 
    "Picked up first page's title");
is(ref($fm->{xml}->{pages}->[0]->{fields}), "ARRAY", 
    "Page's fields are an array");
is(ref($fm->{xml}->{pages}->[0]->{fields}->[0]), "HASH", 
    "Field is a hashref");
is($fm->{xml}->{pages}->[0]->{fields}->[0]->{label}, "first name", 
    "Picked up field title");
is($fm->{xml}{pages}[0]{fields}[0]{description}, "description here", 
    "Picked up field description");
print "Charset parsing tests:\n";
is(ref($fm2->{xml}), "HASH", "parse_xml gives us a hash");
is($fm2->{xml}->{title}, "FormMagick demo application", 
    "Picked up form title");
is(ref($fm2->{xml}->{pages}), "ARRAY", 
    "parse_xml gives us an array of pages");
is(ref($fm2->{xml}->{pages}->[0]), "HASH", 
    "each page is a hashref");
is($fm2->{xml}->{pages}->[0]->{name}, "Personal", 
    "Picked up first page's name");
is($fm2->{xml}->{pages}->[0]->{title}, "Personal details", 
    "Picked up first page's title");
is(ref($fm2->{xml}->{pages}->[0]->{fields}), "ARRAY", 
    "Page's fields are an array");
is(ref($fm2->{xml}->{pages}->[0]->{fields}->[0]), "HASH", 
    "Field is a hashref");
is($fm2->{xml}->{pages}->[0]->{fields}->[0]->{label}, "first name", 
    "Picked up field title");
is($fm2->{xml}{pages}[0]{fields}[0]{description}, "description here", 
    "Picked up field description");

=cut

sub parse_xml {
    my $self = shift;

    my $p;    
    if ($self->{charset})



( run in 1.349 second using v1.01-cache-2.11-cpan-364913b4093 )