1package MogileFS::Class;
2use strict;
3use warnings;
4use MogileFS::Util qw(throw);
5use MogileFS::Checksum;
6
7=head1
8
9MogileFS::Class - Class class.
10
11=cut
12
13sub new_from_args {
14    my ($class, $args, $domain_factory) = @_;
15    return bless {
16        domain_factory => $domain_factory,
17        mindevcount => 2,
18        %{$args},
19    }, $class;
20}
21
22# Instance methods:
23
24sub id   { $_[0]{classid} }
25sub name { $_[0]{classname} }
26sub mindevcount { $_[0]{mindevcount} }
27sub dmid { $_[0]{dmid} }
28sub hashtype { $_[0]{hashtype} }
29sub hashname { $MogileFS::Checksum::TYPE2NAME{$_[0]{hashtype}} }
30
31sub hashtype_string {
32    my $self = shift;
33    $self->hashtype ? $self->hashname : "NONE";
34}
35
36sub repl_policy_string {
37    my $self = shift;
38    return $self->{replpolicy} ? $self->{replpolicy}
39        : 'MultipleHosts()';
40}
41
42sub repl_policy_obj {
43    my $self = shift;
44    if (! $self->{_repl_policy_obj}) {
45        my $polstr = $self->repl_policy_string;
46        # Parses the string.
47        $self->{_repl_policy_obj} =
48            MogileFS::ReplicationPolicy->new_from_policy_string($polstr);
49    }
50    return $self->{_repl_policy_obj};
51}
52
53sub domain {
54    my $self = shift;
55    return $self->{domain_factory}->get_by_id($self->{dmid});
56}
57
58sub has_files {
59    my $self = shift;
60    return Mgd::get_store()->class_has_files($self->{dmid}, $self->id);
61}
62
63sub observed_fields {
64    return {};
65}
66
671;
68