| 1 | package Audio::DB::Factory; | ||
| 2 | |||
| 3 | use strict 'vars'; | ||
| 4 | use Carp 'croak'; | ||
| 5 | use vars '@ISA'; | ||
| 6 | |||
| 7 | use Audio::DB::Util::Rearrange; | ||
| 8 | |||
| 9 | # Objects can either be created with a pre-fetched jasj reference | ||
| 10 | # or with an object id (like an album id). | ||
| 11 | |||
| 12 | sub new { | ||
| 13 | my ($self,@p) = @_; | ||
| 14 | my ($class,$data) = rearrange([qw/CLASS DATA/],@p); | ||
| 15 | |||
| 16 | # Yuck - I need to transform the class (which is really a table name) into | ||
| 17 | # a package name. Stupidity reins supreme | ||
| 18 | # THIS MIGHT BE DEPRECATED NOW BUT LEAVE IN PLACE SO THAT PEOPLE | ||
| 19 | # can call the Factory with artist or artists. | ||
| 20 | |||
| 21 | $class =~ s/s$//; | ||
| 22 | my $package = "Audio::DB::DataTypes::" . ucfirst $class; | ||
| 23 | |||
| 24 | my $this = bless {},$package; | ||
| 25 | foreach (keys %$data) { | ||
| 26 | $this->{$_} = $data->{$_} | ||
| 27 | } | ||
| 28 | return $this; | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | 1; | ||
| 33 |