



Annotate this POD (2)



New  13
Open  16
Stalled  12
View/Report Bugs
Source   Latest Release: DBIx-Class-0.08901-TRIAL


DBIx::Class::Schema - composable schemas


  package Library::Schema;

  # load all Result classes in Library/Schema/Result/

  package Library::Schema::Result::CD;


  # Elsewhere in your code:
  my $schema1 = Library::Schema->connect(
    { AutoCommit => 1 },








Arguments: %options?

   result_namespace => 'Res',
   resultset_namespace => 'RSet',

With no arguments, this method uses Module::Find to load all your Result classes from a sub-namespace Result under your Schema class' namespace, i.e. with a Schema of MyDB::Schema all files in MyDB::Schema::Result are assumed to be Result classes.

It also finds all ResultSet classes in the namespace ResultSet and loads them into the appropriate Result classes using for you. The matching is done by assuming the package name of the ResultSet class is the same as that of the Result class.


  load_namespaces found ResultSet class $classname with no corresponding Result class



Both of the sub-namespaces are configurable if you don't like the defaults, via the options result_namespace and resultset_namespace.

If (and only if) you specify the option default_resultset_class, any found Result classes for which we do not find a corresponding ResultSet class will have their resultset_class set to default_resultset_class.

All of the namespace and classname options to this method are relative to the schema classname by default. To specify a fully-qualified name, prefix it with a literal +.



  # Override everything to use ugly names.
  #   resultset_class set to My::Schema::RSetBase
    result_namespace => 'Res',
    resultset_namespace => 'RSets',
    default_resultset_class => 'RSetBase',

  # Put things in other namespaces

If you'd like to use multiple namespaces of each type, simply use an arrayref of namespaces for that option. In the case that the same result (or resultset) class exists in multiple namespaces, the latter entries in your list of namespaces will override earlier ones.








   Failed to load $comp_class. Can't find source_name method. Is
   or make your load_classes call more specific.





Return value: $storage_type|{$storage_type, \%args}





Arguments: $code_reference
Return value: $code_reference
Default value: None

If exception_action is set for this class/object, "throw_exception" will prefer to call this code reference with the exception as an argument, rather than "throw" in DBIx::Class::Exception.

Your subroutine should probably just wrap the error in the exception object/class of your choosing and rethrow. If, against all sage advice, you'd like your exception_action to suppress a particular exception completely, simply have it return true.


   package My::Schema;
   use My::ExceptionClass;

   # or:

   # suppress all exceptions, like a moron:
   $schema_obj->exception_action(sub { 1 });


Arguments: boolean



Arguments: $sqlt_schema






Arguments: @connectinfo
Return Value: $new_schema







Arguments: $source_name
Return Value: $resultset



Return Value: @source_names
  my @source_names = $schema->sources;

Lists names of all the sources registered on this Schema object.


Arguments: $source_name
Return Value: $result_source



Arguments: $source_name
Return Value: $classname

Retrieves the Result class name for the given source name.


Arguments: $coderef, @coderef_args?
Return Value: The return value of $coderef




Connecting with AutoCommit => 1 is recommended.










  my $storage = $schema->storage;



Arguments: $source_name, \@data;
Return value: \@$objects | nothing

Pass this method a resultsource name, and an arrayref of arrayrefs. The arrayrefs should contain a list of column names, followed by one or many sets of matching data for the given columns.

In void context, insert_bulk in DBIx::Class::Storage::DBI is used to insert the data, as this is a fast method. However, insert_bulk currently assumes that your datasets all contain the same type of values, using scalar references in a column in one row, and not in another will probably not work.

Otherwise, each set of data is inserted into the database using "create" in DBIx::Class::ResultSet, and a arrayref of the resulting row objects is returned.


  $schema->populate('Artist', [
    [ qw/artistid name/ ],
    [ 1, 'Popular Band' ],
    [ 2, 'Indie Band' ],

Since wantarray context is basically the same as looping over $rs->create(...) you won't see any performance benefits and in this case the method is more for convenience. Void context sends the column information directly to storage using <DBI>s bulk insert method. So the performance will be much better for storages that support this method.

Because of this difference in the way void context inserts rows into your database you need to note how this will effect any loaded components that override or augment insert. For example if you are using a component such as DBIx::Class::UUIDColumns to populate your primary keys you MUST use wantarray context if you want the PKs automatically created.


Arguments: @args
Return Value: $new_schema



Overload connection to change the behaviour of connect.


Arguments: $target_namespace, $additional_base_class?
Retur Value: $new_schema





will produce the output

  My::Schema::CD, Base::Class
  My::Schema::Artist, Base::Class








Return Value: $new_schema



Arguments: $message

Throws an exception. Defaults to using Carp::Clan to report errors from user's perspective. See "exception_action" for details on overriding this method's behavior. If "stacktrace" is turned on, throw_exception's default behavior will provide a detailed stack trace.


Arguments: \%sqlt_args, $dir





Return value: $listofstatements







Return value: $normalised_filename






 really need to maintain backward compatibility, you can do the following
 in any overriding methods:





This doesn't actually do anything more than call "freeze" in Storable, it is just provided here for symmetry.


Arguments: $object
Return Value: dcloned $object





Arguments: $moniker, $component_class




  $schema->register_source($moniker, $component_class->result_source_instance);


Arguments: $moniker, $result_source

This method is called by "register_class".

Registers the DBIx::Class::ResultSource in the schema with the given moniker.


Arguments: $moniker

Removes the DBIx::Class::ResultSource from the schema for the given moniker.


Arguments: $moniker, $result_source


compose_connection (DEPRECATED)

Arguments: $target_namespace, @db_info
Return Value: $new_schema

DEPRECATED. You probably wanted compose_namespace.

Actually, you probably just wanted to call connect.


Matt S. Trout <>



syntax highlighting: