use Bugzilla::Group;
use Bugzilla::Error;
+use base qw(Bugzilla::Object);
+
use constant DEFAULT_CLASSIFICATION_ID => 1;
###############################
#### Initialization ####
###############################
+use constant DB_TABLE => 'products';
+
use constant DB_COLUMNS => qw(
products.id
products.name
products.defaultmilestone
);
-my $columns = join(", ", DB_COLUMNS);
-
-sub new {
- my $invocant = shift;
- my $class = ref($invocant) || $invocant;
- my $self = {};
- bless($self, $class);
- return $self->_init(@_);
-}
-
-sub _init {
- my $self = shift;
- my ($param) = @_;
- my $dbh = Bugzilla->dbh;
-
- my $id = $param unless (ref $param eq 'HASH');
- my $product;
-
- if (defined $id) {
- detaint_natural($id)
- || ThrowCodeError('param_must_be_numeric',
- {function => 'Bugzilla::Product::_init'});
-
- $product = $dbh->selectrow_hashref(qq{
- SELECT $columns FROM products
- WHERE id = ?}, undef, $id);
-
- } elsif (defined $param->{'name'}) {
-
- trick_taint($param->{'name'});
- $product = $dbh->selectrow_hashref(qq{
- SELECT $columns FROM products
- WHERE name = ?}, undef, $param->{'name'});
- } else {
- ThrowCodeError('bad_arg',
- {argument => 'param',
- function => 'Bugzilla::Product::_init'});
- }
-
- return undef unless (defined $product);
-
- foreach my $field (keys %$product) {
- $self->{$field} = $product->{$field};
- }
- return $self;
-}
###############################
#### Methods ####
#### Accessors ######
###############################
-sub id { return $_[0]->{'id'}; }
-sub name { return $_[0]->{'name'}; }
sub description { return $_[0]->{'description'}; }
sub milestone_url { return $_[0]->{'milestoneurl'}; }
sub disallow_new { return $_[0]->{'disallownew'}; }
#### Subroutines ######
###############################
-sub get_all_products {
- my $dbh = Bugzilla->dbh;
-
- my $ids = $dbh->selectcol_arrayref(q{
- SELECT id FROM products ORDER BY name});
-
- my @products;
- foreach my $id (@$ids) {
- push @products, new Bugzilla::Product($id);
- }
- return @products;
-}
-
sub check_product {
my ($product_name) = @_;
use Bugzilla::Product;
my $product = new Bugzilla::Product(1);
- my $product = new Bugzilla::Product('AcmeProduct');
+ my $product = new Bugzilla::Product({ name => 'AcmeProduct' });
my @components = $product->components();
my $groups_controls = $product->group_controls();
=head1 DESCRIPTION
-Product.pm represents a product object.
+Product.pm represents a product object. It is an implementation
+of L<Bugzilla::Object>, and thus provides all methods that
+L<Bugzilla::Object> provides.
+
+The methods that are specific to C<Bugzilla::Product> are listed
+below.
=head1 METHODS
=over
-=item C<new($param)>
-
- Description: The constructor is used to load an existing product
- by passing a product id or a hash.
-
- Params: $param - If you pass an integer, the integer is the
- product id from the database that we want to
- read in. If you pass in a hash with 'name' key,
- then the value of the name key is the name of a
- product from the DB.
-
- Returns: A Bugzilla::Product object.
-
=item C<components()>
Description: Returns an array of component objects belonging to
=over
-=item C<get_all_products()>
-
- Description: Returns all products from the database.
-
- Params: none.
-
- Returns: Bugzilla::Product object list.
-
=item C<check_product($product_name)>
Description: Checks if the product name was passed in and if is a valid
=back
+=head1 SEE ALSO
+
+L<Bugzilla::Object>
+
=cut