Monday June 02, 2003
07:20 AM
Discovering Class::Contract
Whilst looking for an existing wheel for an application today, as opposed to writing my own, I came across
Class::Contract on
CPAN - This module allows for the explicit definition of a class interface in a higher-level pseudo-language which allows for a clear definition of input data and method behaviour. This explicit defintion of syntax for the definition of attributes, methods and class constructors fulfilled my needs perfectly, allowing for a clean module package which provides an easy way of defining multiple accessors for class variables with pre-method validation of supplied parameters.
I did however run into a number of problems in using this module:
- The first was that the tied array interface which is used for array attributes does not incorporate a
SPLICE method. This has meant that when modifying an underlying array object through this class, I have been required to copy the array to a temporary array prior to modification by splice and back to the arry object afterwards. - The second problem which I encountered was that under perl 5.005.03 on Solaris, Class::Contract methods failed to return any values. That is, methods defined by the
contract method of Class::Contract did not return any values - The same code worked unmodified under perl 5.6.0 on the same machine without issue. When searching through the CPAN Testers results for this module, I could not find any tests performed on a 5.005.03 platform - Whilst outdated, this platform does form the core platform for the production environment for a number of enterprise environments. Perhaps I should set up a test box running 5.005.03?
Overall, I must say though, I really like the concept of implementing a class interface by contract - If only it could write all of my tests for me as well ...
Discovering Class::Contract 0 Comments More | Login | Reply /