NAME

WWW::Myspace::MyBase - Base class for WWW::Myspace modules

VERSION

Version 0.1

SYNOPSIS

This is a base class that can be used for all WWW::Myspace modules. It provides basic, standardized options parsing in several formats. It validates data using Params::Validate.

To use this in your new module, you simply subclass this module, add the "default_options" method to define your data, and write your methods.

package WWW::Myspace::MyModule;
use WWW::Myspace::MyBase -Base;

const default_options => { happiness => 1, # Required
		count => { default => 50 }, # Not required, defaults to 50
	};

field 'happiness';
field 'count';

sub mymethod {
	if ( $self->happiness ) { print "I'm happy" }
}


People can then call your method with:
$object = new WWW::Myspace::MyModule( happiness => 5 );

or

$object = new WWW::Myspace::MyModule( { happiness => 5 } );

See Params::Validate for more info on the format of, and available parsing stunts available in, default_options.

METHODS

default_options

This method returns a hashref of the available options and their default values. The format is such that it can be passed to Params::Validate (and, well it is :).

You MUST override this method to return your default options. Fortunately we use Spiffy, so you just have to do this:

const default_options => {
		option => { default => value },
		option => { default => value },
};

positional_parameters

If you need to use positional paramteres, define a "positional_parameters" method that returns a reference to a list of the parameter names in order, like this:

const positional_parameters => [ "username", "password" ];

new

Initialze and return a new object. $myspace is a WWW::Myspace object.

We accept the following formats: new - Just creates and returns the new object. new( $myspace ) - Where $myspace is a WWW::Myspace object. new( $myspace, $options_hashref ) - Myspace object followed by a hashref of option => value pairs new( $options_hashref ) new( %options ); new( @options ); - Each option passed is assigned in order to the keys of the "DEFAULT_OPTIONS" hash. new( 'config_file' => "/path/to/file", 'config_file_format' => 'YAML' ); - File format can be "YAML" (see YAML.pm) or "CFG" (see Config::General). - Defaults to "YAML" if not specified.

If you specify options and a config file, the config file will be read, and any options you explicitly passed will override the options read from the config file.

parse_options

This method is called by new to determine the format of the options passed and return a hash of option=>value pairs. If needed, you can call it yourself using the same formats described in "new" above.

$object->new;
$object->parse_options( 'username' => $username,
	'config_file' => "/path/to/file" );

read_config_file

This method is called by parse_options. If a "config_file" argument is passed, this method is used to read options from it. Currently supports CFG and YAML formats.

myspace

Sets/retreives the myspace object with which we're logged in. You probably don't need to use this as you'll pass it to the new method instead.

AUTHOR

Grant Grueninger, <grantg at cpan.org>

BUGS

Please report any bugs or feature requests to bug-www-myspace at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Myspace. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

NOTES

You currently have to both specify the options in default_options and create accessor methods for those you want accessor methods for (i.e. all of them). This should be made less redundant.

We probably want to include cache_dir and possibile cache_file methods here.

TO DO

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc WWW::Myspace::MyBase

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2005 Grant Grueninger, all rights reserved.

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