NAME
PGObject::Composite - Composite Type Mapper for PGObject
VERSION
Version 1.0.2
SYNOPSIS
This module provides a more object-oriented type of interface for writing stored procedures for PostgreSQL than the Simple mapper. The Composite mapper assumes that the object calling the call_dbmethod function usually wants its type on the first argument. Thus we provide an extra function where this is not the case (call_dbfunction).
So we given a cumposite type:
CREATE TYPE foo AS (bar int, baz text);
and a stored procedure:
CREATE OR REPLACE FUNCTION int(foo) returns int language sql as $$
SELECT length($1.baz) + $1.bar;
$$;
We can have a package:
package mycomposite;
use PGObject::Composite;
sub new {
my $pkg = shift;
bless shift, $pkg;
}
sub to_int {
my $self = shift;
my ($ref) = $shelf->call_dbmethod(funcname => 'int');
return shift values %$ref;
}
SUBROUTINES/METHODS
new
This constructs a new object. Basically it copies the incoming hash (one level deep) and then blesses it. If the hash passed in has a dbh member, the dbh is set to that. This does not set the function prefix, as this is assumed to be done implicitly by subclasses.
set_dbh
Sets the database handle
dbh
returns the dbh of the object
associate
Assocates the current object with another PGObject-based class
default_dbh
returns the dbh used by default. Subclasses must override.
default_schema
returns the schema used by default. defaalt is 'public'
default_prefix
returns the prefix used by default. Default is empty string
default_registry
Returns the registry used by default. Default is 'default'
call_dbmethod
Calls a mapped method with the current object as the argument named "self."
This allows for stored procedurs to differentiate what is related to a related type and what is not.
call_procedure
Maps to PGObject::call_procedure with appropriate defaults.
INTERFACES TO OVERRIDE
_get_schema
Defaults to public. This is the type's schema
_get_funcschema
defaults to public.
_get_typename
The name of the composite type. Must be set.
_get_dbh
The database connection to use. Must be set.
AUTHOR
Chris Travers, <chris at efficito.com>
BUGS
Please report any bugs or feature requests to bug-pgobject-composite at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PGObject-Composite. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc PGObject::Composite
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2014 Chris Travers.
This program is distributed under the (Revised) BSD License: http://www.opensource.org/licenses/BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Chris Travers's Organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.