NAME
WebService::GData - Google data protocol v2 base object to inherit.
SYNOPSIS
package WebService::MyService;
use WebService::GData;#strict/warnings turned on
use base 'WebService::GData';
#this is the base implementation of the __init method in WebService::GData
#it is call when new() is used. only overwrite it if necessary.
sub __init {
my ($this,%params) = @_;
while(my ($prop,$val)=each %params){
$this->{$prop}=$val;
}
return $this;
}
WebService::GData::install_in_package([qw(firstname lastname age gender)],sub {
my $func = shift;
return sub {
my $this = shift;
return $this->{$func};
}
});
#the above is equal to writing these simple getters:
#sub firstname {
# my $this = shift;
# return $this->{firstname};
#}
#sub lastname {
# my $this = shift;
# return $this->{lastname};
#}
#sub age {
# my $this = shift;
# return $this->{age};
#}
#sub gender {
# my $this = shift;
# return $this->{gender};
#}
1;
use WebService::MyService;
my $object = new WebService::MyService(name=>'test');
$object->name;#test
#overloaded string will dump the object with Data::Dumper;
print $object;#$VAR1 = bless( { 'name' => 'test' }, 'WebService::MyService' );
#__set and __get are used to create automaticly getters and setters
$object->age(24);
$object->age();#24
$object->{age};#24
DESCRIPTION
This package is a blueprint that you should inherit and extend. It offers a basic hashed based object creation via the word new.
All sub classes should be hash based. If you want to pock into the instance, it's easy but everything that is not documented should be considered private. If you play around with undocumented properties/methods and that it changes,upgrading to the new version with all the extra new killer features will be very hard to do.
so...
dont.
The following classes extends WebService::GData to implement their feature:
- WebService::GData::Base
-
Implements the base get/post/insert/update/delete methods for the Google data protocol.
- WebService::GData::ClientLogin
-
Implements the ClientLogin authorization system.
- WebService::GData::Error
-
Represents a Google data protocol Error.
- WebService::GData::Query
-
Implements the basic query parameters and create a query string.
- WebService::GData::Feed
-
Represents the basic tags found in a Atom Feed (JSON format).
A service in progress:
- WebService::GData::YouTube
-
Implements some of the YouTube API functionalities.
CONSTRUCTOR
new
Takes an hash which keys will be attached to the instance. You can also use install_in_package()
to create setters/getters for these parameters.
Parameters
Returns
Example:
my $object = new WebService::GData(firstname=>'doe',lastname=>'john',age=>'123');
$object->{firstname};#doe
METHODS
__init
This method is called by the constructor new()
. This function receives the parameters set in new()
and assign the key/values pairs to the instance. You should overwrite it and add your own logic.
OVERLOAD
__to_string
Overload the stringification quotes and display a dump of the instance by using Data::Dumper. You should overwrite it should you need to create a specific output.
equal
Overload the comparison "==" by checking that boch objects are hosted in the same memory slot.
AUTOLOAD
Calls to undefined methods on instance are catched and dispatch to __get if the call does not contain any parameter or __set if parameters exist. static methods are not supported. You can overwrite these two methods in your package to meet your naming needs. For example, when you call $instance->dont_exist, you look into $instance->{__DONT_EXIST} instead of the default $instance->{dont_exist}.
__get
This method cathes all calls to undefined methods to which no parameters are passed. If you call $instance-
unknown_method>, the __get
method will return $instance-
{unknown_method}> by default. The __get
method gets the instance and the name of the function has parameters.
__set
This method cathes all calls to undefined methods to which parameters are passed. If you call $instance-
unknown_method($val,$val2)>, the __set
method will set the parameters to $instance-
{unknown_method}> by default. When several parameters are passed, they are saved as an array reference. The __get
method gets the instance and the name of the function has parameters.
SUBS
install_in_package
subnames:ArrayRef
- Should list the name of the methods you want to install in the package.callback:Sub
- The callback will receive the name of the function. This callback should itself send back a function.package_name:Scalar
(optional) - Add functions at distance by specifying an other module.void
Install in the package the methods/subs specified. Mostly use to avoid writting boiler plate getter/setter methods.
Parameters
Returns
Example:
package Basic::User;
use WebService::GData;
use base 'WebService::GData';
#install simple setters; it could also be setter/getters
WebService::GData::install_in_package([qw(firstname lastname age gender)],sub {
my $func = shift;#firstname then lastname then age...
return sub {
my $this = shift;
return $this->{$func};
}
});
1;
#in user code:
my $user = new Basic::User(firstname=>'doe',lastname=>'john',age=>100,gender=>'need_confirmation');
$user->age;#100
$user->firstname;#doe
private
Create a method that is private to the package. Calling a private function from outside of the package will throw an error.
You can import the private method:
use WebService::GData 'private';
Parameters
Returns
void
Throws
error:RefHash
- an hash containing the code: 'forbidden_access' and the content:'private method called outside of its package'.
Example:
package Basic::User;
use WebService::GData 'private';
use base 'WebService::GData';
private my_secret_method => sub {
}; #note the comma
1;
#in user code:
my $user = new Basic::User();
$user->my_secret_method();#throw an error
eval {
$user->my_secret_method();
};
if(my $error = $@){
#$error->{code};
#$error->{content};
}
disable
functions:ArrayRef
- array reference containing the functions to disablepackage:Scalar*
- (optional) By default it uses the package in which it is called but you can specify a package.void
Overwrite a method so that it does nothing... Some namespaces inherit from functionalities that are not required. The function will still be available but will just return the instance.
Parameters
Returns
Example:
package Basic::User;
use WebService::GData;
use base 'WebService::GData::Feed';
WebService::GData::disable([qw(etag title)]);
1;
#in user code:
my $user = new Basic::User();
$user->etag("ddd")->title("dddd");#does nothing at all
BUGS AND LIMITATIONS
If you do me the favor to _use_ this module and find a bug, please email me i will try to do my best to fix it (patches welcome)!
AUTHOR
shiriru <shirirulestheworld[arobas]gmail.com>
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.