~ubuntu-branches/ubuntu/hardy/libcgi-formbuilder-perl/hardy

« back to all changes in this revision

Viewing changes to lib/CGI/FormBuilder.pm

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2007-04-21 21:48:43 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070421214843-1x9e3c92nio0ktvi
Tags: 3.05.01-1
* New upstream release.
  + Fix memory leak affecting Catalyst users.
* Update local cdbs snippets:
  + Add upstream-tarball.mk adding get-orig-source rule and more.
  + Fix overloading buildcore.mk.
  + Check copyrights in prebuild (in clean it may choke on not yet
    cleaned stuff), and make sure it runs only once.
  + List non-binary files affected if discovering new copyrights.
  + Update documentation in debian/README.cdbs-tweaks.
* Fix debian/watch file:
  + Fix version mangling (regex implicitly matches against full ver).
  + Extend main regex to match both tar.gz and tgz used in most recent
    release (using horrible regex due to limitations in file format).

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
use strict;
13
13
use warnings;
14
14
no  warnings 'uninitialized';
 
15
use Scalar::Util qw(weaken);
15
16
 
16
17
use CGI::FormBuilder::Util;
17
18
use CGI::FormBuilder::Field;
18
19
use CGI::FormBuilder::Messages;
19
20
 
20
 
our $VERSION = '3.05';
21
 
our $REVISION = do { (my $r='$Revision: 91 $') =~ s/\D+//g; $r };
 
21
our $VERSION = '3.0501';
 
22
our $REVISION = do { (my $r='$Revision: 100 $') =~ s/\D+//g; $r };
22
23
our $AUTOLOAD;
23
24
 
24
25
# Default options for FormBuilder
276
277
            # init a new one
277
278
            $fprop{name} = "$_";
278
279
            $_ = $self->new_field(%fprop);
 
280
            weaken($_->{_form});
279
281
        }
280
282
        debug 2, "push \@(@ftmp), $_";
281
 
        $self->{fieldrefs}{"$_"} = $_;
 
283
        weaken($self->{fieldrefs}{"$_"} = $_);
282
284
        push @ftmp, $_;
283
285
    }
284
286
 
375
377
    # if we're still in here, we need to init a new field
376
378
    # push it onto our mail fields array, just like initfields()
377
379
    my $f = $self->new_field(%$args);
378
 
    $self->{fieldrefs}{"$f"} = $f;
 
380
    weaken($self->{fieldrefs}{"$f"} = $f);
 
381
    weaken($f->{_form});
 
382
    weaken($f->{fieldrefs}{"$f"});
379
383
    push @{$self->{fields}}, $f;
 
384
    
380
385
    return $f->value;
381
386
}
382
387
 
403
408
            $args->{$k} = $v;
404
409
        }
405
410
    }
406
 
 
 
411
    
407
412
    my $f = CGI::FormBuilder::Field->new($self, $args);
408
413
    debug 1, "created field $f";
409
414
    return $f;   # already set args above ^^^
502
507
 
503
508
    # Forcibly require - no extra time in normal case, and if 
504
509
    # using Apache::Request this needs to be loaded anyways.
505
 
    return '' if $::TESTING;
 
510
    return "Content-type: text/html\n\n" if $::TESTING;
506
511
    require CGI;
507
512
    return  CGI::header(%head);    # CGI.pm MOD_PERL fanciness
508
513
}
925
930
function $jsname (form) {
926
931
    var alertstr = '';
927
932
    var invalid  = 0;
 
933
    var invalid_fields = new Array();
928
934
 
929
935
EOJ1
930
936
    if (invalid > 0 || alertstr != '') {
931
937
EOJ2
932
938
 
933
939
        # Check to see if we have our own jserror callback on form failure
934
 
        # if not, then use the builtin one
 
940
        # if not, then use the builtin one. Aka jsalert
935
941
        if (my $jse = $self->jserror) {
936
 
            $jsfunc .= "        return $jse(form, invalid, alertstr);\n";
 
942
            $jsfunc .= "        return $jse(form, invalid, alertstr, invalid_fields);\n";
937
943
        } else {
938
944
            # Finally, close our JavaScript if it was opened, wrapping in <script> tags
939
945
            # We do a regex trick to turn "%s" into "+invalid+"
1467
1473
        $ref = 'HASH';  # tricky
1468
1474
        debug 2, "rewrote 'template' option since found filename";
1469
1475
    }
1470
 
 
1471
1476
    # Get ourselves ready
1472
1477
    $self->{prepare} = $self->prepare;
1473
 
 
 
1478
    # weaken($self->{prepare});
 
1479
    
1474
1480
    my $opt;
1475
1481
    if ($ref eq 'HASH') {
1476
1482
        # must copy to avoid destroying
1498
1504
    puke "Bad template engine $mod: $@" if $@;
1499
1505
 
1500
1506
    # create new object
 
1507
    #CGI::FormBuilder::Template::Builtin
 
1508
    
1501
1509
    my $tmpl = $mod->new($opt);
1502
 
 
1503
1510
    # Experiemental: Alter tag names as we're rendering, to support 
1504
1511
    # Ajaxian markup schemes that use their own tags (Backbase, Dojo, etc)
1505
1512
    local %CGI::FormBuilder::Util::TAGNAMES;
1507
1514
        $CGI::FormBuilder::Util::TAGNAMES{$k} = $v;
1508
1515
    }
1509
1516
 
 
1517
 
1510
1518
    # Call the engine's prepare too, if it exists
1511
1519
    # Give it the form object so it can do what it wants
1512
1520
    # This will have all of the prepared data in {prepare} anyways
1513
1521
    if ($tmpl && UNIVERSAL::can($tmpl, 'prepare')) {
1514
1522
        $tmpl->prepare($self);
1515
1523
    }
 
1524
    
 
1525
 
1516
1526
 
1517
1527
    # dispatch to engine, prepend header
1518
1528
    debug 1, "returning $tmpl->render($self->{prepare})";
1519
 
    return $self->header . $tmpl->render($self->{prepare});
 
1529
 
 
1530
    my $ret = $self->header . $tmpl->render($self->{prepare});
 
1531
    
 
1532
    #we have a circular reference but we need to kill it after setting up return
 
1533
    weaken($self->{prepare});
 
1534
    return $ret;
1520
1535
}
1521
1536
 
1522
1537
# These routines should be moved to ::Mail or something since they're rarely used