Shaun Guth > Interface-Param-0.1 > Interface::Param

Download:
Interface-Param-0.1.tar.bz2

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 0.1   Source   Latest Release: Interface-Param-0.2

NAME ^

Interface::Param - Plug-n-play param()-style methods

DESCRIPTION ^

This abstract class allows you to quickly and easily add a method to your objects which stores key/value pairs and allows you to retrieve them. The functionality is not unlike the param() method from CGI.pm (which you're probably familiar with).

SYNOPSIS ^

 package MyObject;
 use base qw(MyParent Interface::Param);
 use warnings;
 use strict;

 sub set_defaults
 {
    my $self = shift;
    $self->options( 'sounds' => 0, 'level' => 1, 'volume' => 50 );
 }

 sub print_volume
 {
    my $self = shift;
    print $self->options( 'volume' );
 }

 # create a param method called options 
 sub options
 {
    my $self = shift;
    return $self->_param( '__options', @_ );
 }

 1;

METHODS ^

_param

This is the core of the Interface::Param package. You simply pass this method a name to store the data under, and then the arguments your custom param method received, and it will do the rest. Accepts input to store as a list, hashref, or hash. It also accepts input as an arrayref which is handled differently. Each element of the arrayref is set as the key and value. If passed one key, will return value of that key. If passed no arguments, will return all keys currently stored.

_delete_param

Takes a name of your data store and a field and deletes it from the stored data

_clear_param

Takes a name of your data store and clears all elements of it.

CREDITS ^

I'm pretty sure I borrowed this routine (if not the code, then the idea) from another module on CPAN, but I can't for the life of me remember which one. If anybody ever reads this and recognizes it let me know so I can give the author credit.

AUTHOR ^

Shaun Guth <l8nite@l8nite.net>

LICENSE ^

Copyright (C) 2004 Shaun Guth

This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.