1 package MogileFS
::Factory
::Class
;
4 use base
'MogileFS::Factory';
6 use MogileFS
::NewClass
;
8 # This class is a reimplementation since classids and classnames
9 # are not globally unique... uses the same interface.
12 my ($self, $domain, $args) = @_;
13 my $domain_factory = MogileFS
::Factory
::Domain
->get_factory;
14 # FIXME: Inject the dmid into the class somehow.
15 my $class = MogileFS
::NewClass
->new_from_args($args, $domain_factory);
16 $self->{by_id
}->{$domain->id}->{$class->id} = $class;
17 $self->{by_name
}->{$domain->id}->{$class->name} = $class;
21 # Example of what we could use for testing.
22 # Test creates the object, injects its own factory, then hands it to us.
24 my ($self, $obj) = @_;
30 my $domid = $class->domain->id;
31 my $clsid = $class->id;
32 if (exists $self->{by_id
}->{$domid}->{$clsid}) {
33 delete $self->{by_id
}->{$domid}->{$clsid};
34 delete $self->{by_name
}->{$domid}->{$class->name};
39 my ($self, $domain, $id) = @_;
40 return $self->{by_id
}->{$domain->id}->{$id};
44 my ($self, $domain, $name) = @_;
45 return $self->{by_name
}->{$domain->id}->{$name};
49 my ($self, $domain) = @_;
50 return keys %{$self->{by_id
}->{$domain->id}};
54 my ($self, $domain) = @_;
55 return keys %{$self->{by_name
}->{$domain->id}};
59 my ($self, $domain) = @_;
60 return values %{$self->{by_id
}->{$domain->id}};
64 my ($self, $domain) = @_;
65 my $set = $self->{by_id
}->{$domain->id};
66 return { map { $_ => $set->{$_} } keys %{$set} };
70 my ($self, $domain) = @_;
71 my $set = $self->{by_name
}->{$domain->id};
72 return { map { $_ => $set->{$_} } keys %{$set} };