Merge branch 'master' of https://github.com/solgenomics/sgn
[sgn.git] / cgi-bin / scraps / test.pl
blobf2dc304770b6c614a2642c041da758e3ecd98697
1 use CXGN::Page;
2 use CXGN::Scrap;
3 use Carp;
6 ## Everything a scrap does should be enclosed in an eval{} statement to catch errors.
7 eval {
9 my $scrap = CXGN::Scrap->new();
11 my %args = $scrap->get_all_encoded_arguments();
13 print<<HTML;
15 <html>
16 <head><title>Scrap Test</title></head>
17 <body style='font-family:arial, sans-serif'>
18 This page is a scrap. It uses <b>CXGN::Scrap</b> as opposed to <b>CXGN::Page</b> to grab arguments. This reduces overhead for things we don't need, such as standard SGN/Secretary page headers and footers.
19 <br><br>
20 The purpose of scraps is to receive arguments and perform database-related actions behind the scenes. Generally, a scrap receives it's request via an <b>AJAX</b> method in <b>Javascript</b>. It should return some kind of simple textual reply that can be parsed by Javascript, but it doesn't really have to print anything at all.
21 <br><br>
22 This page wouldn't be an ideal scrap for Javascript-parsing since it contains html tagging and a little css, but you get the idea.
23 <br><br>
24 Try the following link to make sure the argument-getting is working:
25 <a href='test.pl?something=intheway&esta_bien=1&yadda=kostanza'>This page, w/ args</a>
26 &nbsp;&nbsp;
27 <a href='test.pl'>This page, no args</a>
28 <br><br>
29 Here is a list of arguments sent to this scrap:
30 HTML
32 while(my($key, $value) = each %args) {
33 print "<br><em>Key:</em> $key => <em>Value:</em> $value";
38 print <<EOF;
39 <br><br>
40 Here is the code for this page. Notice that all of the scrap methods are enclosed in eval{} tags, so that an AJAX request does not receive an SGN error page, but rather a more simple Error expression that is parse-able:
42 <pre>
43 use CXGN::Page;
44 use CXGN::Scrap;
45 use Carp;
47 ## Everything a scrap does should be enclosed in an eval{} statement to catch errors.
48 eval {
50 my \$scrap = CXGN::Scrap->new();
52 my \%args = \$scrap->get_all_encoded_arguments();
54 print\<\<HTML;
56 <html>
57 <head><title>Scrap Test</title></head>
59 ... Everything you see above ...
61 Here is a list of arguments sent to this scrap:
62 HTML
64 while(my(\$key, \$value) = each \%args) {
65 print "Key: \$key => Value: \$value";
68 print <<HTML;
69 </body></html>
70 HTML
72 ## This is the preferred method for scraps to generate errors. The standard SGN error page will be very difficult for Javascript to parse, in case a die, confess, or croak gets called.
73 if(\$@) {
74 print "Error: \$@";
75 ##Everytime a scrap messes up, the AJAX request will begin with "Error:". This allows JS-side error-catching to be handled fairly easily.
78 EOF
81 ## This is the preferred method for scraps to generate errors. The standard SGN error page will be very difficult for Javascript to parse, in case a die, confess, or croak gets called.
82 if($@) {
83 print "Error: $@";
84 ##Everytime a scrap messes up, the AJAX request will begin with "Error:". This allows JS-side error-catching to be handled fairly easily.