Name

File::DataClass::ResultSet - Core result management methods

Synopsis

   use File:DataClass;

   my $attr = { result_source_attributes => { schema_attributes => { ... } } };

   my $result_source = File::DataClass->new( $attr )->result_source;

   my $rs = $result_source->resultset( { path => q(path_to_data_file) } );

   my $result = $rs->search( $hash_ref_of_where_clauses );

   for my $result_object ($result->next) {
      # Do something with the result object
   }

Description

Find, search and update methods for element objects

Configuration and Environment

Defines these attributes

list_class

List class name, defaults to File::DataClass::List

result_class

Result class name, defaults to File::DataClass::Result

result_source

An object reference to the File::DataClass::ResultSource instance that created this result set

_iterator

Contains the integer count of the position within the _results hash. Incremented by each call to "next"

_operators

A hash ref of coderefs that implement the comparison operations performed by the "search" method

_results

An array of result objects. Produced by calling "search"

Subroutines/Methods

all

   @results = $rs->search()->all;

Returns all the result object references that were found by the "search" call

create

   $result_object_ref = $rs->create( $args );

Creates and inserts an new record. The $args hash requires the id of the record to create. Missing attributes are defaulted from the defaults attribute of the File::DataClass::Schema object. Returns the new record's object reference

This behaviour changed after 0.41. It used to return the new record id

create_or_update

   $result_object_ref = $rs->create_or_update( $args );

Creates a new record if it does not already exist, updates the existing one if it does. Returns the record's object reference

This behaviour changed after 0.41. It used to return the record id

delete

   $record_id = $rs->delete( $id_of_record_to_delete );
   $record_id = $rs->delete( { id => $record_to_delete, optional => $bool } );

Deletes a record. Returns the id of the deleted record. By default the optional flag is false and if the record does not exist an exception will be thrown. Setting the flag to true avoids the exception and undef is returned instead

find

   $result_object_ref = $rs->find( $id_of_record_to_find } );

Finds the named record and returns an result object reference for it

find_and_update

   $result_object_ref = $rs->find_and_update( $args );

Finds the named result object and updates it's attributes

This behaviour changed after 0.41. It used to return the result id

first

   $result_object_ref = $rs->search( $where_clauses )->first;

Returns the first result object that was found by the /search call

list

   $list_object_ref = $rs->list( { id => $id } );

Returns a list object reference

Retrieves the named record and a list of record ids

last

   $result_object_ref = $rs->search( $where_clauses )->last;

Returns the last result object that was found by the /search call

next

   $result_object_ref = $rs->search( $where_clauses )->next;

Iterate over the results returned by the /search call

path

   $path = $rs->path;

Attribute "path" in File::DataClass::Schema

push

   $added = $rs->push( { name => $id, list => $list, items => $items } );

Adds items to the attribute list. The $args hash requires these keys; id the element to edit, list the attribute of the named element containing the list of existing items, req the request object and items the field on the request object containing the list of new items

reset

   $rs->reset

Resets the resultset's cursor, so you can iterate through the search results again

   $result = $rs->search( $hash_ref_of_where_clauses );

Search for records that match the given criterion. The criterion is a hash reference whose keys are record attribute names. The criterion values are either scalar values or hash references. The scalar values are tested for equality with the corresponding record attribute values. Hash reference keys are treated as comparison operators, the hash reference values are compared with the record attribute values, e.g.

   { 'some_element_attribute_name' => { '>=' => 0 } }

select

   $hash = $rs->select;

Returns a hash ref of records

splice

   $removed = $rs->splice( { name => $id, list => $list, items => $items } );

Removes items from the attribute list

storage

   $storage = $rs->storage;

Attribute "storage" in File::DataClass::Schema

update

   $rs->update( { id => $of_element, fields => $attr_hash } );

Updates the named element

_txn_do

Calls "txn_do" in File::DataClass::Storage

Diagnostics

None

Dependencies

File::DataClass::List
File::DataClass::Result

Incompatibilities

There are no known incompatibilities in this module

Bugs and Limitations

There are no known bugs in this module. Please report problems to the address below. Patches are welcome

Author

Peter Flanigan, <pjfl@cpan.org>

License and Copyright

Copyright (c) 2017 Peter Flanigan. All rights reserved

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

This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE