The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Pinwheel::Fixtures

SYNOPSIS

    use Pinwheel::Fixtures;
    fixtures('episodes', 'brands', 'series', 'networks');
    scenario('radio4_empty_schedule');

The episodes.yml file might resemble:

    radio4:
      id: 1
      name: When Frogs Go Berserk
      short_description: This is the short description
      long_description: This is the long description of the episode
      pid: pid001
      series_id: 1
      position: 1

DESCRIPTION

Pinwheel::Fixtures provides a mechanism for loading YAML files into the database. Database access is via the Pinwheel::Database module.

The convention is the same as in Rails: the name of the YAML file is the name of the database table. The first element in the YAML is an identifier for the tuple. Each item for the tuple should be a row in the database using its field name.

ROUTINES

fixtures(NAMES)

TODO, properly document me.

This method is called to import the fixture data for the database tables specified as a list of fieldnames.

scenario(NAME, OPTIONS)

TODO, properly document me.

Import a collection of fixtures in one go. If called with an OPTIONS value of root => 0 then fixtures at the root of the fixture directory are ignored.

$int = identify($string)

Hashes $string to some integer. This can be used to automatically pick IDs that would normally be generated automatically by the database.

empty_tables()

Empties all the tables in the database. (Specifically, uses DELETE to do so).

insert_fixtures($fixtures, $table)

Loads the data given by $fixtures into the given database $table.

Enumerates the columns in the given $table. Columns named (created|updated)_(at|on) are assigned a default of the current time. Any integer columns named like *_id are deemed to be foreign keys.

For each $label, $row in %$fixtures (where $row is a hash ref of column name / value pairs):

  • If the table has an 'id' column and there is no 'id' entry in $row, the id is filled in using identify($label).

  • For each column identified as a foreign key, if the value in $row is present but contains any non-digit characters, then the value is replaced by identify($value).

  • The row is then written to the database (using REPLACE INTO).

EXPORTS

Exported by default: fixtures scenario identify

May be exported: insert_fixtures empty_tables

BUGS

The documentation doesn't describe how the fixtures are loaded, and how 'helpers' are used. The synopsis mentions "the episodes.yaml" file, without first mentioning that YAML is even used.

AUTHOR

A&M Network Publishing <DLAMNetPub@bbc.co.uk>