File: Recipe.pm

package info (click to toggle)
libdata-objectdriver-perl 0.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 784 kB
  • sloc: perl: 3,795; sql: 64; makefile: 7
file content (44 lines) | stat: -rw-r--r-- 918 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# $Id$

package Recipe;
use strict;
use base qw( Data::ObjectDriver::BaseObject );
use DodTestUtil;

use Data::ObjectDriver::Driver::DBI;
use Ingredient;
use Ingredient2Recipe;

__PACKAGE__->install_properties({
    columns => [ 'recipe_id', 'title' ],
    datasource => 'recipes',
    primary_key => 'recipe_id',
    driver => Data::ObjectDriver::Driver::DBI->new(
        dsn      => DodTestUtil::dsn('global'),
    ),
});

sub add_ingredient_by_name {
    my $recipe = shift;
    my($name, $quantity) = @_;

    my $ingredient = Ingredient->new;
    $ingredient->name($name);
    $ingredient->quantity($quantity);
    $ingredient->save;

    $recipe->add_ingredient($ingredient);

    $ingredient;
}

sub add_ingredient {
    my $recipe = shift;
    my($ingredient) = @_;
    my $map = Ingredient2Recipe->new;
    $map->ingredient_id($ingredient->id);
    $map->recipe_id($recipe->recipe_id);
    $map->save;
}

1;