Rose-DB-Object

 view release on metacpan or  search on metacpan

lib/Rose/DB/Object/Metadata.pm  view on Meta::CPAN


use Rose::DB::Object::Util qw(lazy_column_values_loaded_key);
use Rose::DB::Object::Constants 
  qw(PRIVATE_PREFIX STATE_IN_DB MODIFIED_COLUMNS);

use Rose::DB::Object::ConventionManager;
use Rose::DB::Object::ConventionManager::Null;
use Rose::DB::Object::Metadata::PrimaryKey;
use Rose::DB::Object::Metadata::UniqueKey;
use Rose::DB::Object::Metadata::ForeignKey;
use Rose::DB::Object::Metadata::Column::Scalar;
use Rose::DB::Object::Metadata::Relationship::OneToOne;

# Attempt to load Scalar::Util::Clone at runtime and ignore any errors
# to keep it from being a "hard" requirement.
eval { local $@; require Scalar::Util::Clone };

use Clone(); # This is the backup clone method

our $VERSION = '0.820';

our $Debug = 0;

#
# Object data
#

use Rose::Object::MakeMethods::Generic
(
  scalar => 
  [
    'class',
    'error',
    'pre_init_hook',
    'post_init_hook',
    '_object_default_manager_base_class',
  ],

  'scalar --get_set_init' =>
  [
    'db',
    'db_id',
    'primary_key',
    'column_name_to_method_name_mapper',
    'original_class',
    'auto_prime_caches',
  ],

  boolean => 
  [
    allow_inline_column_values  => { default => 0 },
    is_initialized              => { default => 0 },
    is_auto_initializating      => { default => 0 },
    allow_auto_initialization   => { default => 0 },
    was_auto_initialized        => { default => 0 },
    initialized_foreign_keys    => { default => 0 },
    default_load_speculative    => { default => 0 },
    auto_load_related_classes   => { default => 1 },
    default_update_changes_only => { default => 0 },
    default_insert_changes_only => { default => 0 },
    default_cascade_save        => { default => 0 },
    default_smart_modification  => { default => 0 },
    include_predicated_unique_indexes => { default => 0 },
  ],

  'array --get_set_inited' =>
  [
    'columns_ordered',
    'nonpersistent_columns_ordered',
  ]
);

#
# Class data
#

use Rose::Class::MakeMethods::Generic
(
  inheritable_scalar => 
  [
    'dbi_prepare_cached',
    'default_column_undef_overrides_default',
    '_class_default_manager_base_class',
  ],

  inheritable_hash =>
  [
    column_type_classes => { interface => 'get_set_all' },
    column_type_names   => { interface => 'keys', hash_key => 'column_type_classes' },
    _column_type_class  => { interface => 'get_set', hash_key => 'column_type_classes' },
    _delete_column_type_class => { interface => 'delete', hash_key => 'column_type_classes' },

    auto_helper_classes      => { interface => 'get_set_all' },
    delete_auto_helper_class => { interface => 'delete', hash_key => 'auto_helper_classes' },

    relationship_type_classes => { interface => 'get_set_all' },
    relationship_type_class   => { interface => 'get_set', hash_key => 'relationship_type_classes' },
    delete_relationship_type_class => { interface => 'delete', hash_key => 'relationship_type_classes' },

    class_registry => => { interface => 'get_set_all' },

    convention_manager_classes => { interface => 'get_set_all' },
    convention_manager_class   => { interface => 'get_set', hash_key => 'convention_manager_classes' },
    delete_convention_manager_class => { interface => 'delete', hash_key => 'convention_manager_classes' },
  ],
);

__PACKAGE__->default_manager_base_class('Rose::DB::Object::Manager');
__PACKAGE__->dbi_prepare_cached(1);

__PACKAGE__->class_registry({});

__PACKAGE__->auto_helper_classes
(
  'informix' => 'Rose::DB::Object::Metadata::Auto::Informix',
  'pg'       => 'Rose::DB::Object::Metadata::Auto::Pg',
  'mysql'    => 'Rose::DB::Object::Metadata::Auto::MySQL',
  'sqlite'   => 'Rose::DB::Object::Metadata::Auto::SQLite',
  'oracle'   => 'Rose::DB::Object::Metadata::Auto::Oracle',
  'generic'  => 'Rose::DB::Object::Metadata::Auto::Generic',
);

lib/Rose/DB/Object/Metadata.pm  view on Meta::CPAN

=item B<column_accessor_method_names>

Returns a list (in list context) or a reference to the array (in scalar context) of the names of the "set" methods for all the columns, in the order that the columns are returned by L<column_names|/column_names>.

=item B<column_aliases [MAP]>

Get or set the hash that maps column names to their aliases.  If passed MAP (a list of name/value pairs or a reference to a hash) then MAP replaces the current alias mapping.  Returns a reference to the hash that maps column names to their aliases.

Note that modifying this map has no effect if L<initialize|/initialize>, L<make_methods|/make_methods>, or L<make_column_methods|/make_column_methods> has already been called for the current L<class|/class>.

=item B<column_mutator_method_name NAME>

Returns the name of the "set" method for the column named NAME.  This is just a shortcut for C<$meta-E<gt>column(NAME)-E<gt>mutator_method_name>.

=item B<column_mutator_method_names>

Returns a list (in list context) or a reference to the array (in scalar context) of the names of the "set" methods for all the columns, in the order that the columns are returned by L<column_names|/column_names>.

=item B<column_names>

Returns a list (in list context) or a reference to an array (in scalar context) of column names.

=item B<column_name_to_method_name_mapper [CODEREF]>

Get or set the code reference to the subroutine used to map column names to  method names.  If undefined, then the L<init_column_name_to_method_name_mapper|/init_column_name_to_method_name_mapper> class method is called in order to initialize it.  If...

If defined, the subroutine should take four arguments: the metadata object, the column name, the column method type, and the method name that would be used if the mapper subroutine did not exist.  It should return a method name.

=item B<column_rw_method_name NAME>

Returns the name of the "get_set" method for the column named NAME.  This is just a shortcut for C<$meta-E<gt>column(NAME)-E<gt>rw_method_name>.

=item B<column_rw_method_names>

Returns a list (in list context) or a reference to the array (in scalar context) of the names of the "get_set" methods for all the columns, in the order that the columns are returned by L<column_names|/column_names>.

=item B<column_undef_overrides_default [BOOL]>

Get or set a boolean value that influences the default value of the L<undef_overrides_default|Rose::DB::Object::Metadata::Column/undef_overrides_default> attribute for each L<column|/columns> in this L<class|/class>.  See the documentation for L<Rose...

Defaults to the value returned by the L<default_column_undef_overrides_default|/default_column_undef_overrides_default> class method.

=item B<convention_manager [ OBJECT | CLASS | NAME ]>

Get or set the convention manager for this L<class|/class>.  Defaults to the return value of the L<init_convention_manager|/init_convention_manager> method.

If undef is passed, then a L<Rose::DB::Object::ConventionManager::Null> object is stored instead.

If a L<Rose::DB::Object::ConventionManager>-derived object is passed, its L<meta|Rose::DB::Object::ConventionManager/meta> attribute set to this metadata object and then it is used as the convention manager for this L<class|/class>.

If a L<Rose::DB::Object::ConventionManager>-derived class name is passed, a new object of that class is created with its L<meta|Rose::DB::Object::ConventionManager/meta> attribute set to this metadata object.  Then it is used as the convention manage...

If a convention manager name is passed, then the corresponding class is looked up in the L<convention manager class map|convention_manager_classes>, a new object of that class is constructed, its L<meta|Rose::DB::Object::ConventionManager/meta> attri...

See the L<Rose::DB::Object::ConventionManager> documentation for more information on convention managers.

=item B<db>

Returns the L<Rose::DB>-derived object associated with this metadata object's L<class|/class>.  A fatal error will occur if L<class|/class> is undefined or if the L<Rose::DB> object could not be created.

=item B<default_cascade_save [BOOL]>

Get or set a boolean value that indicates whether or not the L<class|/class> associated with this metadata object will L<save|Rose::DB::Object/save> related objects when the parent object is L<saved|Rose::DB::Object/save>.  See the documentation for ...

=item B<default_load_speculative [BOOL]>

Get or set a boolean value that indicates whether or not the L<class|/class> associated with this metadata object will L<load|Rose::DB::Object/load> speculatively by default.  See the documentation for L<Rose::DB::Object>'s L<load()|Rose::DB::Object/...

=item B<default_update_changes_only [BOOL]>

Get or set a boolean value that indicates whether or not the L<class|/class> associated with this metadata object will L<update|Rose::DB::Object/update> only an object's modified columns by default (instead of updating all columns).  See the document...

=item B<delete_column NAME>

Delete the column named NAME.

=item B<delete_columns>

Delete all of the L<columns|/columns>.

=item B<delete_column_type_class TYPE>

Delete the type/class L<mapping|/column_type_classes> entry for the column type TYPE.

=item B<delete_convention_manager_class NAME>

Delete the name/class L<mapping|/convention_manager_classes> entry for the convention manager class mapped to NAME.

=item B<delete_nonpersistent_column NAME>

Delete the L<non-persistent column|/nonpersistent_columns> named NAME.

=item B<delete_nonpersistent_columns>

Delete all of the L<nonpersistent_columns|/nonpersistent_columns>.

=item B<delete_relationship NAME>

Delete the relationship named NAME.

=item B<delete_relationships>

Delete all of the relationships.

=item B<delete_relationship_type_class TYPE>

Delete the type/class mapping entry for the relationship type TYPE.

=item B<delete_unique_keys>

Delete all of the unique key definitions.

=item B<error_mode [MODE]>

Get or set the error mode of the L<Rose::DB::Object> that fronts the table described by this L<Rose::DB::Object::Metadata> object.  If the error mode is false, then it defaults to the return value of the C<init_error_mode> method, which is "fatal" by...

The error mode determines what happens when a L<Rose::DB::Object> method encounters an error.  The "return" error mode causes the methods to behave as described in the L<Rose::DB::Object> documentation.  All other error modes cause an action to be pe...

Valid values of MODE are:

=over 4



( run in 0.538 second using v1.01-cache-2.11-cpan-39bf76dae61 )