{"id":1884,"date":"2018-11-10T17:42:51","date_gmt":"2018-11-10T09:42:51","guid":{"rendered":"http:\/\/ufqi.com\/blog\/?p=1884"},"modified":"2018-11-10T17:43:36","modified_gmt":"2018-11-10T09:43:36","slug":"gwa2perl-try-catch-backref","status":"publish","type":"post","link":"https:\/\/ufqi.com\/blog\/gwa2perl-try-catch-backref\/","title":{"rendered":"GWA2Perl\u7814\u53d1\uff1atry-catch\u65e0\u6cd5\u9000\u51fa\u5faa\u73af\u3001\u65b9\u6cd5\u4f20\u53c2\u5f15\u7528\u4f20\u503c\u53ca\u591a\u6570\u636e\u5e93\u94fe\u63a5"},"content":{"rendered":"<p style=\"text-align: center\">\u5728\u4f7f\u7528 GWA2Perl \u5f00\u53d1\u65f6\u9047\u5230\u4e00\u4e9b\u7834\u8d39\u5468\u6298\u624d\u53d1\u73b0\u7684 Bug\u6216\u6539\u8fdb\u7684\u529f\u80fd\uff0c\u5206\u6790\u8bb0\u5f55\u5982\u4e0b\uff0c\u5907\u5fd8\u3002 GWA2 \u662f\u4e00\u5957\u8de8\u8bed\u8a00\u7684\u7f51\u7edc\u5e94\u7528\u8f6f\u4ef6\u5f00\u53d1\u6846\u67b6\uff0c\u76ee\u524d\u6709PHP\u3001Java\u548cPerl\u7248\u672c\u53ef\u4f9b\u4e0b\u8f7d\u9009\u7528\uff0c\u4e5f\u5373 GWA2PHP, GWA2Java \u548c GWA2Perl\u3002<\/p>\n<p><strong>1. \u5e94\u7528 Tiny::Try \u7684Catch\u6a21\u5757\u65e0\u6cd5\u6267\u884c\u9000\u51fa\u5faa\u73af\u7684\u95ee\u9898<\/strong><\/p>\n<blockquote>\n<p>&#8230;<br \/>use Tiny::Try<br \/>&#8230;.<br \/>foreach my $i(keys %alist){<br \/>try{<br \/>\u00a0 \u00a0 # something<br \/>}<br \/>catch{<br \/>\u00a0 \u00a0 if(aCondition==1){<br \/>\u00a0 \u00a0 \u00a0 \u00a0 next; # cannot?<br \/>\u00a0 \u00a0 }<br \/>}<br \/>}<br \/>&#8230;<\/p>\n<\/blockquote>\n<p>\u6b64\u5904\u7684 next \u65e0\u6cd5\u6309\u9884\u671f\u6267\u884c. \u6539\u8fdb\u7684\u63aa\u65bd\u662f\uff0c\u9884\u5148\u9876\u4e00\u4e2a $tryresult = 0; \u7136\u540e\u5728\u6210\u529f\u7684\u65f6\u5019\uff0c\u5c06 $tryresult =1; \u5728 try::catch \u6267\u884c\u5b8c\u6bd5\u4e4b\u540e\u518d\u5bf9 $tryresult \u8fdb\u884c\u5224\u65ad\uff0c\u4ee5\u51b3\u5b9a\u662f\u5426\u9000\u51fa\u5faa\u73af. \u4fee\u6539\u540e\u7684\u4ee3\u7801\u5927\u81f4\u5982\u4e0b\u3002<\/p>\n<blockquote>\n<p>&#8230;<br \/>use Tiny::Try<br \/>&#8230;.<br \/>foreach my $i(keys %alist){<br \/><strong>my $tryresult = 1;<\/strong><br \/>try{<br \/>\u00a0 \u00a0 # something<br \/>}<br \/>catch{<br \/>\u00a0 \u00a0 if(aCondition==1){<br \/>\u00a0 \u00a0 \u00a0 \u00a0 next; # cannot?<br \/>\u00a0 \u00a0 }<br \/>\u00a0 \u00a0 <strong>$tryresult = 0;<\/strong><br \/>}<br \/><strong>if($tryresult == 0){<\/strong><br \/><strong>\u00a0 \u00a0 next;<\/strong><br \/><strong>}<\/strong><br \/>}<br \/>&#8230;<\/p>\n<\/blockquote>\n<p><strong>2. Perl\u65b9\u6cd5\u4f20\u9012\u53c2\u6570\u5e94\u7528\u4f20\u503c\u7684\u95ee\u9898<\/strong><\/p>\n<p>my %alist = (&#8216;a&#8217;=&gt;1, &#8216;b&#8217;=&gt;2);<br \/><strong>&amp;functionA(\\%alist);<\/strong><br \/>&amp;functionA(%alist); # wrong!<br \/>&amp;functionA($alist) # wrong!<\/p>\n<p>my $blist = \\%alist;<br \/><strong>&amp;functionA($blist);<\/strong><br \/>&amp;functionA(\\%blist); # wrong!<\/p>\n<p>Perl\u7684\u65b9\u6cd5\u53c2\u6570\u4f20\u9012\u95ee\u9898\uff0c\u5728\u6b64\u524d\u7684\u8d34\u6587\u4e2d\u8fdb\u884c\u8fc7\u76f8\u5e94\u7684\u8ba8\u8bba\uff0c\u5982\u00a0<b><a class=\"bigfont\" href=\"https:\/\/ufqi.com\/naturedns\/search?q=-R\/H2SP\" target=\"_blank\">-R\/H2SP<\/a>\u00a0\u548c\u00a0<a href=\"https:\/\/ufqi.com\/naturedns\/search?q=-R\/32SJ\">-R\/32SJ <\/a>, <\/b>\u8fd9\u6b21\u91cd\u65b0\u518d\u4e09\u7684\u63d0\u53ca\uff0c\u4e3b\u8981\u8fd8\u662f\u7531\u4e8e\u5728Perl\u7684\u53c2\u6570\u4f20\u9012\u8fc7\u7a0b\u4e2d\uff0c\u6781\u6613\u53d1\u751f\u8bef\u89e3\uff0c\u5bf9Perl\u4f9d\u9760\u5f62\u5f0f\u6765\u83b7\u53d6\u6570\u636e\u7c7b\u578b\u7684\u505a\u6cd5\u8ba4\u8bc6\u7684\u4e0d\u591f\u6df1\u523b\u3002\u5982\u7ed9\u5b9a\u540c\u4e00\u4e2a\u53d8\u91cf\u540d\u79f0\uff0c\u53ef\u80fd\u8868\u8ff0\u4e0d\u540c\u7684\u610f\u601d\u3002<\/p>\n<p>$varA = undef; &#8211;&gt; \u4e00\u4e2a\u666e\u901a\u7684\u672a\u77e5\u7c7b\u578b\u7684\u53d8\u91cf varA\uff1b<br \/>$varA[0] &#8211;&gt;\u00a0 \u4e00\u4e2a\u6570\u7ec4\u53d8\u91cf varA ;<br \/>$varA{&#8216;a&#8217;} &#8211;&gt; \u4e00\u4e2a\u54c8\u5e0c\u53d8\u91cf varA ;<br \/>$varA = []; &#8211;&gt; \u4e00\u4e2ahashref\u53d8\u91cf varA;<\/p>\n<p>\u6b63\u662f\u8fd9\u79cd\u968f\u610f\u6027\u4f7f\u5f97Perl\u8bed\u8a00\u7684\u53d8\u91cf\u638c\u63e1\u8d77\u6765\u8ba9\u4eba\u5bb9\u6613\u51fa\u9519\uff0c\u518d\u7ed3\u5408\u4f20\u503c\u6216\u8005\u4f20\u5f15\u7528\uff0c\u8ff7\u60d1\u6027\u66f4\u5927\u3002<\/p>\n<p><strong>3. Perloop\/Perlobj \u9762\u5411\u5bf9\u8c61\u7684Perl\u8fdb\u884c\u591a\u6570\u636e\u5e93\u540c\u65f6\u8fde\u63a5\u7684\u95ee\u9898<\/strong><\/p>\n<p><strong>3.1.\u95ee\u9898\u63cf\u8ff0<\/strong><br \/>\u5728 GWA2Perl\u7684\u5b9e\u73b0\u4e2d\uff0c\u5bf9\u8c61\u8fde\u63a5\u6570\u636e\u5e93\u901a\u8fc7 WebApp &#8211;&gt; Dba &#8211;&gt; Conn &#8211;&gt; Driver \u7684\u8fc7\u7a0b(\u00a0<a class=\"bigfont\" href=\"https:\/\/ufqi.com\/naturedns\/search?q=-R\/12SL\" target=\"_blank\">-R\/12SL<\/a>\u00a0 )\u3002 \u8bbe\u82e5\u6709\u5bf9\u8c61ObjectA\uff0c\u9700\u8981\u8fde\u63a5\u6570\u636e\u5e93DatabaseA\uff1b \u6709\u5bf9\u8c61ObjectB\uff0c\u9700\u8981\u8fde\u63a5\u6570\u636e\u5e93DatabaseB\u3002<br \/>\u5728\u6b64\u8bbe\u7f6e\u4e0b\uff0c\u82e5\u5355\u72ec\u8fd0\u884c\u5b9e\u4f8b\u5316\u7684 ObjectA\uff0c\u6216\u8005ObjectB\u5747\u6ca1\u6709\u95ee\u9898\uff0c\u6216\u8005\u540c\u65f6\u8fd0\u884cObjectA\/ObjectB\uff0c\u540c\u65f6\u8fde\u63a5\u5230\u6570\u636e\u5e93DatabaseA\uff0c\u4e5f\u6ca1\u6709\u95ee\u9898\u3002 \u5f53\u6211\u4eec\u5e0c\u671b\u540c\u65f6\u8fd0\u884c\u5b9e\u4f8b\u5316\u7684ObjectA\/ObjectB\uff0c\u5e76\u5206\u522b\u8fde\u63a5\u6570\u636e\u5e93DatabaseA\/DatabaseB\u65f6\uff0c\u95ee\u9898\u5c31\u53d1\u751f\u4e86\uff0cPerl\u7684\u8fd0\u884c\u65f6\u73af\u5883\u4e2d\uff0c\u603b\u662f\u7559\u5b58\u6700\u540e\u4e00\u4e2a\u6d3b\u8dc3\u7684\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\u3002<br \/>\u7c7b\u4f3c\u7684\u95ee\u9898\u5e76\u4e0d\u4f1a\u5728\u975ePerlOOP\u7684\u73af\u5883\u4e2d\u4ea7\u751f\uff0c\u5982\u679c\u5728\u901a\u8fc7\u7684\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u58f0\u660e\u4e0d\u540c\u7684 $dbi \u5b9e\u4f8b\u6765\u6620\u5c04\u5230\u4e0d\u540c\u7684\u6570\u636e\u5e93\u8fde\u63a5\u4e0a\uff0c\u5e76\u4fdd\u6301\u5230\u4e00\u4e2asession\u6267\u884c\u7ed3\u675f\u6216\u8005\u624b\u5de5\u5173\u95ed\u3002\u6bd4\u5982 $dbiDatabaseA \u8fde\u63a5\u5230DatabaseA\u4e0a\uff0c$dbiDatabaseB\u8fde\u63a5\u5230DatabaseB\u4e0a\u3002<\/p>\n<p><strong>3.2. \u901a\u8fc7\u5bf9\u8c61\u5b9e\u4f8b\u7684UniqueId\u6765\u533a\u522b\u5b9e\u4f8b<\/strong><br \/>\u6839\u636e\u5bf9\u95ee\u9898\u7684\u63cf\u8ff0\uff0c\u5728 PerlOOP\u4e2d\uff0c\u5b9e\u4f8b\u5316\u540e\u7684\u5bf9\u8c61\u5171\u4eab\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u5982\u679c\u5176\u4e2d\u4ee5\u53c2\u6570\u7684\u65b9\u5f0f\u5e26\u5165\u4e0d\u540c\u7684\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\uff0c\u5b9e\u4f8b\u5316\u540e\u5bf9\u8c61\u7684\u65e0\u6cd5\u4fdd\u6301\u6570\u636e\u5e93\u4fe1\u606f\u4e0e\u5177\u4f53\u5b9e\u4f8b\u7684\u5bf9\u5e94\u5173\u7cfb\u3002<br \/>\u89e3\u51b3\u7684\u601d\u8def\u662f\u5728 WebApp\u4e00\u5c42\u589e\u52a0\u5982\u4e0b\u8bbe\u65bd\uff1a<br \/>1) + getUniqueId<br \/>2) + _checkDbConn<br \/>\u5176\u4e2d 1) \u662f\u5728\u5bf9\u8c61\u5b9e\u4f8b\u5316\u540e\u6839\u636e\u5bf9\u8c61 Scalar::Util \u7684\u65b9\u6cd5 refaddr \u6765\u83b7\u53d6\u5bf9\u8c61\u7684\u552f\u4e00 Id\u53f7\uff0c\u7136\u540e\u5728 WebApp \u4e2d\uff0c\u5b9e\u73b0\u5bf9\u8c61\u4e0e\u6570\u636e\u5e93\u4fe1\u606f\u505a\u7ed1\u5b9a\uff1b<br \/>2) \u5728 WebApp \u4e2d\u6bcf\u5f53\u8fdb\u884c\u6570\u636e\u5e93\u8bfb\u5199\u64cd\u4f5c\u65f6\uff0c\u83b7\u53d6\u5f53\u524d\u5b9e\u4f8b\u5316\u5bf9\u8c61\u7684 \u552f\u4e00Id\uff0c\u7136\u540e\u4ece\u73af\u5883\u53d8\u91cf %hmf \u4e2d\u83b7\u5f97\u5176\u7ed1\u5b9a\u7684 \u6570\u636e\u5e93\u4fe1\u606f\uff0c\u4ece\u6570\u636e\u5e93\u5bf9\u8c61 $dba \u4e2d\u83b7\u5f97\u5f53\u524d\u6d3b\u8dc3\u7684\u6570\u636e\u5e93\u4fe1\u606f\uff0c\u7136\u540e\u5bf9\u4e24\u8005\u505a\u6bd4\u8f83\uff0c\u5f53\u4e24\u8005\u76f8\u7b26\u65f6\uff0c\u7ee7\u7eed\u524d\u884c\uff1b\u5f53\u4e24\u8005\u4e0d\u4e00\u81f4\u65f6\uff0c\u91cd\u7f6e\/\u5207\u6362\u6570\u636e\u5e93\u8fde\u63a5\u81f3\u5b9e\u4f8b\u5316\u5bf9\u8c61\u6240\u7ed1\u5b9a\u7684\u6570\u636e\u5e93\u4e0a\u3002<br \/>\u4e5f\u8bb8\u8fd9\u662f\u4e34\u65f6\u89e3\u51b3\u65b9\u6848\uff0c\u5728\u540e\u7eed\u7684PerlOOP\u4e2d\u80fd\u5f97\u5230\u89e3\u51b3\uff0c\u6216\u8005\u5728 Perl 6\u4e2d\u80fd\u591f\u5c06\u5bf9\u8c61\u5c01\u88c5\u7684\u66f4\u4e25\u5bc6\u4e9b\u3002<\/p>\n<p><strong>3.3 \u5b9e\u4f8b\u5316\u540e\u7684\u5bf9\u8c61\u6839\u636e\u552f\u4e00Id\u6269\u5c55<\/strong><br \/>\u5b9e\u73b0\u4e86\u53ef\u4ee5\u540c\u65f6\u64cd\u4f5c\u591a\u4e2a\u6570\u636e\u5e93\u7684PerlOOP\uff0cGWA2Perl\u7684\u80fd\u529b\u5c06\u8fdb\u4e00\u6b65\u6269\u589e\uff0c\u5176\u4ed6\u7c7b\u4f3c\u7684\u8d44\u6e90\u8bfb\u53d6\u5747\u53ef\u4ee5\u5b9e\u73b0\u591a\u6e90\u8bfb\u53d6\uff0c\u5982Session\uff0cCache\uff0cFile\u7b49\u5176\u4ed6\u7f51\u7edc\u8d44\u6e90\u3002<br \/>\u8fd9\u4e00\u95ee\u9898\u662f\u7b2c\u4e8c\u6b21\u78b0\u5230\uff0c\u8d77\u521d\u9047\u5230\u65f6\uff0c\u60f3\u5230\u7684\u662f\u5728\u7a0b\u5e8f\u4e2d\u4e34\u65f6\u5207\u6362\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u5f53\u5176\u65f6\u5e76\u6ca1\u6709\u66f4\u597d\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4eca\u6b21\u6df1\u5165\u5206\u6790\uff0c\u83b7\u5f97\u4e00\u4e2a\u53ef\u4ee5\u81ea\u52a8\u5316\u7684\u6301\u7eed\u89e3\u51b3\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5b9e\u73b0\uff1a<br \/>1) \u540c\u4e00\u4e2a\u5bf9\u8c61\u5728\u4e00\u4e2a\u65f6\u671f\u5185\uff0c\u603b\u662f\u6301\u7eed\u4e00\u81f4\u5730\u7ef4\u6301\u5bf9\u8d44\u6e90\u7684\u8fde\u63a5\uff1b<br \/>2) \u4e0d\u540c\u7684\u5bf9\u8c61\uff0c\u62e5\u6709\u4e0d\u540c\u7684\u8d44\u6e90\u8fde\u63a5\uff0c\u4e14\u53ef\u4ee5\u540c\u65f6\u5e76\u884c\u3002<\/p>\n<p><img src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/09\/gwa2-logo-201606.v2.png\" \/><\/p>\n<p>-GWA2 \u662f\u201d\u901a\u7528\u7f51\u7edc\u5e94\u7528\u67b6\u6784( General Web Application Architeture )\u201d\uff0c\u57fa\u4e8e -GWA2 \u53ef\u4ee5\u8f7b\u4fbf\u6784\u5efa\u5404\u79cd\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f,<br \/>\u5305\u62ec\u590d\u6742\u7684\u5728\u7ebf\u8d2d\u7269\u5546\u57ce\u3001\u00a0\u65c5\u6e38\u4ea4\u6613\u5e73\u53f0\u3001\u793e\u7fa4\u6216\u8005\u793e\u4ea4\u7f51\u7ad9\u548c\u65b0\u95fb\u8d44\u8baf\u7f51\u7ad9\u7b49\uff0c<br \/>\u4e5f\u5305\u62ec\u5404\u79cd\u4f01\u4e8b\u4e1a\u5355\u4f4d\u7f51\u4e0a\u95e8\u6237\uff0c\u5728\u7ebf\u4ea4\u4e92\u53ca\u670d\u52a1\u4f5c\u4e1a\u7cfb\u7edf\u7b49.<br \/>\u8fd8\u53ef\u4ee5\u5305\u62ec\u4e3aNativeApp\u505a\u670d\u52a1\u5668\u7aef\u652f\u6301, \u751a\u81f3\u662fWebApp\u7684\u5168\u90e8.<br \/>-GWA2 \u662f\u4e3a\u6570\u4e0d\u591a\u7684\u652f\u6301\u8de8\u5f00\u53d1\u8bed\u8a00\u7684\u5e94\u7528\u6846\u67b6\uff0c\u76ee\u524d\u652f\u6301 -Java, -PHP, -Perl, -Aspx and -Python .<\/p>\n<p>-GWA2 is a \u201cGeneral Web Application Architecture\u201d and based on -GWA2 developers can easily build a variety of network applications,<br \/>including complex online shopping malls, travel trading platforms, community or social networking sites and news information sites, etc.<br \/>Also the applications include various online portals of enterprises and institutions, online interaction and service operations systems.<br \/>Moreover it contains server-side support for NativeApp, or even all of the WebApp.<br \/>-GWA2 is one of the web frameworks which provide cross-language support for -Java, -PHP, -Perl, -Aspx and -Python at present.<\/p>\n<p><strong>-GWA2 is E.A.S.Y\u00a0<\/strong><br \/><b>Easy Along, Swift Yield<br \/><\/b>\u8f7b\u677e\u542f\u52a8, \u5feb\u901f\u4ea7\u51fa.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528 GWA2Perl \u5f00\u53d1\u65f6\u9047\u5230\u4e00\u4e9b\u7834\u8d39\u5468\u6298\u624d\u53d1\u73b0\u7684 Bug\u6216\u6539\u8fdb\u7684\u529f\u80fd\uff0c\u5206 &hellip; <a href=\"https:\/\/ufqi.com\/blog\/gwa2perl-try-catch-backref\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[42,6,2],"tags":[86,280,23,286,285],"_links":{"self":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1884"}],"collection":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/comments?post=1884"}],"version-history":[{"count":11,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1884\/revisions"}],"predecessor-version":[{"id":1904,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1884\/revisions\/1904"}],"wp:attachment":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media?parent=1884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/categories?post=1884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/tags?post=1884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}