Bug 6679 - [SIGNED-OFF] fix 2 perlcritic violations in C4/Installer/PerlModules.pm
[koha.git] / C4 / Category.pm
blob8cadc8b6126c9df9e38d76783fb05b89d79a67ad
1 package C4::Category;
3 # Copyright 2009 Liblime
4 # Parts Copyright 2011 Tamil
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 use strict;
22 use warnings;
23 use C4::Context;
25 our $AUTOLOAD;
30 =head1 NAME
32 C4::Category - objects from the categories table
34 =head1 SYNOPSIS
36 use C4::Category;
37 my @categories = C4::Category->all;
38 print join("\n", map { $_->description } @categories), "\n";
40 =head1 DESCRIPTION
42 Objects of this class represent a row in the C<categories> table.
44 Currently, the bare minimum for using this as a read-only data source has
45 been implemented. The API was designed to make it easy to transition to
46 an ORM later on.
48 =head1 API
50 =head2 Class Methods
52 =cut
54 =head3 C4::Category->new(\%opts)
56 Given a hashref, a new (in-memory) C4::Category object will be instantiated.
57 The database is not touched.
59 =cut
61 sub new {
62 my ($class, $opts) = @_;
63 bless $opts => $class;
69 =head3 C4::Category->all
71 This returns all the categories as objects. By default they're ordered by
72 C<description>.
74 =cut
76 sub all {
77 my $class = shift;
78 map {
79 utf8::encode($_->{description});
80 $class->new($_);
81 } @{C4::Context->dbh->selectall_arrayref(
82 "SELECT * FROM categories ORDER BY description", { Slice => {} }
83 )};
89 =head2 Object Methods
91 These are read-only accessors for attributes of a C4::Category object.
93 =head3 $category->categorycode
95 =cut
97 =head3 $category->description
99 =cut
101 =head3 $category->enrolmentperiod
103 =cut
105 =head3 $category->upperagelimit
107 =cut
109 =head3 $category->dateofbirthrequired
111 =cut
113 =head3 $category->finetype
115 =cut
117 =head3 $category->bulk
119 =cut
121 =head3 $category->enrolmentfee
123 =cut
125 =head3 $category->overduenoticerequired
127 =cut
129 =head3 $category->issuelimit
131 =cut
133 =head3 $category->reservefee
135 =cut
137 =head3 $category->category_type
139 =cut
141 sub AUTOLOAD {
142 my $self = shift;
143 my $attr = $AUTOLOAD;
144 $attr =~ s/.*://;
145 if (exists $self->{$attr}) {
146 return $self->{$attr};
147 } else {
148 return undef;
152 sub DESTROY { }
157 =head1 SEE ALSO
159 The following modules make reference to the C<categories> table.
161 L<C4::Members>, L<C4::Overdues>, L<C4::Reserves>
164 =head1 AUTHOR
166 John Beppu <john.beppu@liblime.com>
168 =cut