<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
My questions:<br>
a) Where do I store the intermediate values of the attributes. I can&#39;t put them in the object itself<br>
as it would generate a &quot;invalid&quot; object. Do I store them simply as data somewhere else? Do<br>
I have to create a &quot;proxy&quot; object with lighter rules?<br>
</blockquote><div><br>I wouldn&#39;t. Just instantiate your object at the entry controller and store the instance in the $c-&gt;session, or wherever you find appropiate depending on the object characteristics and the kind of state handling you need. <br>
<br>Do your entry validation as part of the attribute checking validation, as in Moose:<br><br>package MyClass;<br>use Moose;<br>use Moose::Util::TypeConstraints;<br>subtype &#39;AcceptedAge&#39; =&gt; as &#39;Int&#39; =&gt; where { $_ &gt;= 16 } =&gt; message { &#39;You must be at least 16 to use this.&#39; };<br>
subtype &#39;NameStr&#39; =&gt; as &#39;Str&#39; =&gt; where { length($_) &gt; 1 } =&gt; message { &quot;What kinda name is &#39;$_&#39;?&quot; };<br>has &#39;name&#39; =&gt; (is=&gt;&#39;rw&#39;, isa=&gt;&#39;NameStr&#39;, required =&gt; 1 );<br>
has &#39;age&#39; =&gt; (is=&gt;&#39;rw&#39;, isa=&gt;&#39;AcceptedAge&#39;, required =&gt; 1 );<br>has &#39;sex&#39; =&gt; (is=&gt;&#39;rw&#39;, isa=&gt;&#39;Str&#39;, required =&gt; 1 );<br><br>In your (overly-simplified) controller: <br>
<br>sub submit : Local {<br>       $c-&gt;session-&gt;{obj} = new MyClass( $c-&gt;req-&gt;params );  # dies if constraint fails, so trap errors <br>}<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
b) How can I verify attribute rules as early as possible in that &quot;entering&quot; process? Do I have to<br>
dublicate the knowledge of the rules outside the class? (e.g. Length of String attribute less than 20)<br>
The class itself would check such a restriction.<br>
</blockquote><div><br>Then, just finish validating your object in the &quot;exit&quot; controller.<br><br>sub wrap_it_up : Local {<br>     ...<br>     if( $c-&gt;session-&gt;{obj}-&gt;validate ) {<br>         ## yup<br>     } else {<br>
           ## nope<br>    }<br>}<br><br>Back in your class, do the more complex validations:<br><br>sub validate {<br>      return 1 if(  ( $self-&gt;sex eq &#39;F&#39; &amp;&amp; $self-&gt;age &gt;=16 )  ## girls mature earlier...<br>
                       || (  $self-&gt;sex eq &#39;M&#39; &amp;&amp; $self-&gt;age &gt;=18 ) );  <br>}<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
What ways are you going? Which is the &quot;right&quot; OO-way of doing it?</blockquote><div><br><br>TIMTOWTDI<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
At the moment I really don&#39;t know where to place the input validation knowledge and where and how<br>
to store the partly created objects. I hope it sounds not to academic, but I want to clearly seperate<br>
the responsibilities.<br>
</blockquote><div><br>Moose will give you a lot of ammo to help you with this, things such as coersion and roles. Check with the moosers in their maling list for further OO questions. <br><br>On the other hand, if you need client-side validation, take a peek at HTML::FormFu, as it may help you with putting some of those rules on the client side. Catalyst::Model::Adaptor may also come in handy if you feel you need to turn your class into a model.<br>
<br></div></div>-rodrigo<br>