[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[6771] branches/1.3



Revision: 6771
          http://sourceforge.net/p/ledger-smb/code/6771
Author:   einhverfr
Date:     2014-02-06 03:25:22 +0000 (Thu, 06 Feb 2014)
Log Message:
-----------
LedgerSMB::Request backport, only includes requires() and requires_series() API's since these are the only ones 
applicable to 1.3

Modified Paths:
--------------
    branches/1.3/LedgerSMB/Form.pm
    branches/1.3/LedgerSMB.pm

Added Paths:
-----------
    branches/1.3/LedgerSMB/Request.pm

Modified: branches/1.3/LedgerSMB/Form.pm
===================================================================
--- branches/1.3/LedgerSMB/Form.pm	2014-02-05 15:21:43 UTC (rev 6770)
+++ branches/1.3/LedgerSMB/Form.pm	2014-02-06 03:25:22 UTC (rev 6771)
@@ -72,6 +72,7 @@
 use charnames qw(:full);
 use open ':utf8';
 package Form;
+use base 'LedgerSMB::Request';
 use utf8;
 
 use LedgerSMB::Log;

Added: branches/1.3/LedgerSMB/Request.pm
===================================================================
--- branches/1.3/LedgerSMB/Request.pm	                        (rev 0)
+++ branches/1.3/LedgerSMB/Request.pm	2014-02-06 03:25:22 UTC (rev 6771)
@@ -0,0 +1,73 @@
+=head1 NAME
+
+LedgerSMB::Request - Basic request handling routines for LedgerSMB
+
+=head1 SYNPOSIS
+
+   $request->requires('myattribute1', 'myattribute2');
+
+Error:  Attribute 'myattribute2' is not provided.
+
+   $request->requires_series(1, 12, 'myattribute1', 'myattribute2');
+
+=cut
+
+package LedgerSMB::Request;
+use LedgerSMB::App_State;
+use Carp;
+
+=head1 DESCRIPTION
+
+This package provides methods (as an interface package, as of 1.4) for both new
+and old code to use for declarative handling of required inputs, dates, and 
+amounts.
+
+In future versions, this may take on more of the role found in LedgerSMB.pm 
+today, but hopefully with a lot less cruft.  It isn't clear we will use
+CGI::Simple or rely on a specific interface and so some portability in request
+handling will be required.  That's where this module comes in.
+
+=head1 METHODS
+
+=head2 requires(@attribute_names)
+
+Raises an exception if any member of the argument list corresponds to a non-key
+in the current hash or an empty string.  '0' does pass however.
+
+=cut
+
+sub requires {
+    my $self = shift @_;
+    for (@_){
+        Carp::croak(LedgerSMB::App_State->Locale->text("Required attribute not provided: [_1]", $_))
+              unless $self->{$_} or $self->{$_} eq '0';
+    }
+}
+
+=head2 requries_series($start, $stop, @attnames)
+
+Generates and checks a series of attributes in the form of ${attname}_$count
+from $start to $stop, for each in @attnames
+
+=cut
+
+sub requires_series {
+    my $self = shift @_;
+    my $start = shift @_;
+    my $end  = shift @_;
+    for my $att (@_){
+        $self->requires("${att}_$_") for ($start .. $stop);
+    }
+}
+
+=head1 COPYRIGHT
+
+Copyright (C) 2014 The LedgerSMB Core Team.
+
+This file may be re-used under the terms of the GNU General Public License
+version 2 or at your option any later version.  Please see the LICENSE.txt for
+details.
+
+=cut
+
+1;

Modified: branches/1.3/LedgerSMB.pm
===================================================================
--- branches/1.3/LedgerSMB.pm	2014-02-05 15:21:43 UTC (rev 6770)
+++ branches/1.3/LedgerSMB.pm	2014-02-06 03:25:22 UTC (rev 6771)
@@ -222,6 +222,7 @@
 $CGI::Simple::POST_MAX = -1;
 
 package LedgerSMB;
+use base 'LedgerSMB::Request';
 our $VERSION = '1.3.37';
 
 my $logger = Log::Log4perl->get_logger('LedgerSMB');

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits