forked from DizzyDogg/Wilderness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecipeBook.pm
68 lines (56 loc) · 1.46 KB
/
RecipeBook.pm
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package RecipeBook;
use strict;
use warnings;
# use base qw(Object);
use Data::Dumper;
sub new {
my $package = shift;
my $self = {@_};
bless $self, $package;
$self->{'name'} = 'recipebook';
return $self;
}
my $recipe;
my @dirs = ('Item', 'Fixture');
foreach my $dir (@dirs) {
opendir(DIR, $dir) or die $!;
while ( my $file = readdir(DIR) ) {
next if ($file =~ m/^\./);
my $path = "$dir/$file";
my $package = "$dir\::$file";
$package =~ s/\.pm//;
(my $product = $file) =~ s/\.pm//;
$product = lc($product);
require $path;
$recipe->{$product}->{'package'} = $package || '';
$recipe->{$product}->{'ingredients'} = [ $package->get_ingredients() ];
$recipe->{$product}->{'tools'} = [ $package->get_tools() ];
$recipe->{$product}->{'process'} = $package->process() || '';
}
}
sub has_recipe {
my $self = shift;
my $product = shift;
return $recipe->{"$product"} ? $recipe->{"$product"} : undef;
}
sub get_package {
my $self = shift;
my $product = shift;
return $recipe->{$product}->{'package'};
}
sub get_ingredients {
my $self = shift;
my $product = shift;
return @{$recipe->{$product}->{'ingredients'}};
}
sub get_tools {
my $self = shift;
my $product = shift;
return @{$recipe->{$product}->{'tools'}};
}
sub get_process {
my $self = shift;
my $product = shift;
return $recipe->{$product}->{'process'};
}
1;