Pinwheel::Fixtures
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
Pinwheel::Fixtures provides a mechanism for loading YAML files into the database. Database access is via the Pinwheel::Database module.
Pinwheel::Database
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.
TODO, properly document me.
This method is called to import the fixture data for the database tables specified as a list of fieldnames.
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.
root => 0
Hashes $string to some integer. This can be used to automatically pick IDs that would normally be generated automatically by the database.
$string
Empties all the tables in the database. (Specifically, uses DELETE to do so).
DELETE
Loads the data given by $fixtures into the given database $table.
$fixtures
$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.
(created|updated)_(at|on)
*_id
For each $label, $row in %$fixtures (where $row is a hash ref of column name / value pairs):
$label, $row
%$fixtures
$row
If the table has an 'id' column and there is no 'id' entry in $row, the id is filled in using identify($label).
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).
identify($value)
The row is then written to the database (using REPLACE INTO).
Exported by default: fixtures scenario identify
May be exported: insert_fixtures empty_tables
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.
A&M Network Publishing <DLAMNetPub@bbc.co.uk>
To install Pinwheel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pinwheel
CPAN shell
perl -MCPAN -e shell install Pinwheel
For more information on module installation, please visit the detailed CPAN module installation guide.