RoPkg::Object(3pm)

NAME
 RoPkg::Object

VERSION
0.3.2

DESCRIPTION
RoPkg::Object is a general pourpose module, designed for Get/Set objects on which you don't want to spend your time writing annoying Get/Set methods. The primary use of the module is to be a base class.

SYNOPSIS
 package RoPkg::Person;

 use strict;
 use warnings;

 use RoPkg::Object;

 use base qw(RoPkg::Object);

 $pf = {
   FirstName => 'A person first name',
   LastName  => 'A person last name'
 };

 sub new {
   my ($class, %opt) = @_;
   my $self;

   $self = $class->SUPER::new(%opt);
   $self->{methods} = $pf;
   $self->_inject();

   return $self;
 }

 1;

 tester.pl
 #!/usr/bin/perl

 use strict;
 use warnings;

 use English qw(-no_match_vars);
 use RoPkg::Person;

 sub main {
   my $p = new RoPkg::Person();
   $p->FirstName('John');
   $p->LastName('Doe');

   print $p->FirstName,' ',$p->LastName,$RS;
 }

 main();

SUBROUTINES/METHODS
All methods (besides new()) raise OutsiteClass exception if called outside a class instance. Each method, may raise other exceptions. Please read the documentation of that method for aditional information.

  new()
The class contructor. At this moment the constructor does nothing (besides bless).

  key($value)
Search into methods list for a entry those value is $value. Returns the method name or 0 if such a method was not found.

  methods()
In list context this method will return a list of method names. In scalar context returns just the number of methods. Please note that only the valid methods are considered (tested with can($method_name)).

  chkp(@plist)
Check the current object if the parameters specified in the list are defined. If a parameter is not defined a Param::Missing exception is raised.

SUBCLASSING
As said before, this module is specially used as a base class for those objects with many SET/GET methods. How can you use this class in your project ? As seen in the SYNOPSIS, when you create the new class, in the class constructor you call for $self->_inject method, who create (at runtime) the new methods. The list of methods who are gonna be created is actually a hash reference. A method can be specified like this:

 FirstName => q{-}

This means, that _inject will create a get/set method named FirstName. There are some key values with special meaning:

*) __exclude__ - the method with this value will not be created by _inject
*) q{} - the method with this value will not be created by _inject

If a existing method is available in the class and is also included in the list of methods who will be created by _inject, that method will be ignored by _inject. Each method created by _inject() has the following code:

 sub {
   my ($self, $pval) = @_;

   if ( !blessed($self) ) {
     OutsideClass->throw('Called outside class instance');
   }

   if ( defined $pval) {
     $self->{$method_name} = $pval;
   }
   return $self->{$method_name};
 };

DEPENDENCIES
RoPkg::Object require perl 5.008 or later and the Scalar::Util module. To run the tests you also need:

*) Test::More
*) Test::Pod
*) Test::Pod::Coverage

DIAGNOSTICS
This module is subject of tests. To run those tests, unpack the source and use the following command: make test

CONFIGURATION AND ENVIRONMENT
This module does not use any configuration file or environment variables.

INCOMPATIBILITIES
None known to the author

BUGS AND LIMITATIONS
No known bugs. If you find one please send a detailed report to me. Please note that the methods are not automatically created. One must manual call (inside the child object) the method who "injects" the new methods.

PERL CRITIC
This module is perl critic level 1 compliant with 2 exceptions.

AUTHOR
Subredu Manuel <diablo@iasi.roedu.net>

LICENSE AND COPYRIGHT
Copyright (C) 2005 Subredu Manuel. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The LICENSE file contains the full text of the license.