Schema/Result/Inventory.pm

filter: Statementstmt 100% 20 / 20 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 2 / 2 totaltotal 100% 30 / 30 CC 3 SCAR 5.1
CC
3
Cov
100%
decrement
2.0
increment
2.0
BEGIN
1.0
CRAP 1.7
« Schema/Candy.pm ↑ Summary Schema/ResultSet/Tax.pm »
1 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Interchange6::Schema::Result::Inventory;
4  
5 =head1 NAME
6  
7 Interchange6::Schema::Result::Inventory
8  
9 =cut
10  
11 2 ▶use Interchange6::Schema::Candy;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 DESCRIPTION
14  
15 The Inventory class is used to store current stock levels for products.
16  
17 =head1 ACCESSORS
18  
19 =head2 sku
20  
21 The SKU of the product.
22  
23 Primary key and foreign constraint on
24 L<Interchange6::Schema::Result::Product/sku> via L</product> relationship.
25  
26 =cut
27  
28 2 primary_column sku =>
29 { data_type => "varchar", size => 64 };
30  
31 =head2 quantity
32  
33 This is the quantity currently held in stock.
34  
35 Defaults to 0.
36  
37 =cut
38  
39 2 column quantity => { data_type => "integer", default_value => 0 };
40  
41 =head1 RELATIONS
42  
43 =head2 product
44  
45 Type: belongs_to
46  
47 Related object: L<Interchange6::Schema::Result::Product>
48  
49 =cut
50  
51 2 belongs_to
52 product => "Interchange6::Schema::Result::Product",
53 "sku",
54 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" };
55  
56 =head1 METHODS
57  
58  
59 =head2 decrement( $quantity )
60  
61 Atomically reduce L</quantity> by argument or by 1 if argument is not defined.
62 Returns new value of L</quantity>.
63  
64 =cut
65  
66 sub decrement {
67 2 ▶ my ( $self, $quantity ) = @_;
Subroutine decrement: called CC=2 SCAR=6.9
Pod documented
68 2 ▶ $quantity = 1 unless defined $quantity;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $quantity 1 1 2
69 2 $self->update( { quantity => \[ 'quantity - ?', $quantity ] } );
70 2 $self->discard_changes;
71 2 return $self->quantity;
72 }
73  
74 =head2 increment( $quantity )
75  
76 Atomically increase L</quantity> by argument or by 1 if argument is not defined.
77 Returns new value of L</quantity>.
78  
79 =cut
80  
81 sub increment {
82 2 ▶ my ( $self, $quantity ) = @_;
Subroutine increment: called CC=2 SCAR=6.9
Pod documented
83 2 ▶ $quantity = 1 unless defined $quantity;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $quantity 1 1 2
84 2 $self->update( { quantity => \[ 'quantity + ?', $quantity ] } );
85 2 $self->discard_changes;
86 2 return $self->quantity;
87 }
88  
89 2 1;
« Schema/Candy.pm ↑ Summary Schema/ResultSet/Tax.pm »