mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
Add Perl 5 implementation
This commit is contained in:
parent
4967a5606d
commit
0a772512de
74
perl/GildedRose.pm
Normal file
74
perl/GildedRose.pm
Normal file
@ -0,0 +1,74 @@
|
||||
package GildedRose;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ( $class, %attrs ) = @_;
|
||||
return bless \%attrs, $class;
|
||||
}
|
||||
|
||||
sub update_quality {
|
||||
my $self = shift;
|
||||
for my $item ( @{ $self->{items} } ) {
|
||||
if ( $item->{name} ne 'Aged Brie'
|
||||
&& $item->{name} ne 'Backstage passes to a TAFKAL80ETC concert' )
|
||||
{
|
||||
if ( $item->{quality} > 0 ) {
|
||||
if ( $item->{name} ne 'Sulfuras, Hand of Ragnaros' ) {
|
||||
$item->{quality} = $item->{quality} - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( $item->{quality} < 50 ) {
|
||||
$item->{quality} = $item->{quality} + 1;
|
||||
|
||||
if ( $item->{name} eq
|
||||
'Backstage passes to a TAFKAL80ETC concert' )
|
||||
{
|
||||
if ( $item->{sell_in} < 11 ) {
|
||||
if ( $item->{quality} < 50 ) {
|
||||
$item->{quality} = $item->{quality} + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $item->{sell_in} < 6 ) {
|
||||
if ( $item->{quality} < 50 ) {
|
||||
$item->{quality} = $item->{quality} + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $item->{name} ne 'Sulfuras, Hand of Ragnaros' ) {
|
||||
$item->{sell_in} = $item->{sell_in} - 1;
|
||||
}
|
||||
|
||||
if ( $item->{sell_in} < 0 ) {
|
||||
if ( $item->{name} ne 'Aged Brie' ) {
|
||||
if ( $item->{name} ne
|
||||
'Backstage passes to a TAFKAL80ETC concert' )
|
||||
{
|
||||
if ( $item->{quality} > 0 ) {
|
||||
if ( $item->{name} ne 'Sulfuras, Hand of Ragnaros' ) {
|
||||
$item->{quality} = $item->{quality} - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$item->{quality} = $item->{quality} - $item->{quality};
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( $item->{quality} < 50 ) {
|
||||
$item->{quality} = $item->{quality} + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
16
perl/Item.pm
Normal file
16
perl/Item.pm
Normal file
@ -0,0 +1,16 @@
|
||||
package Item;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ( $class, %attrs ) = @_;
|
||||
return bless \%attrs, $class;
|
||||
}
|
||||
|
||||
sub _data_printer { ## no critic (ProhibitUnusedPrivateSubroutines)
|
||||
my ( $self, $properties ) = @_;
|
||||
return $self->{name} . ', ' . $self->{sell_in} . ', ' . $self->{quality};
|
||||
}
|
||||
|
||||
1;
|
||||
18
perl/test.pl
Executable file
18
perl/test.pl
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More 0.96;
|
||||
|
||||
use_ok 'GildedRose';
|
||||
use_ok 'Item';
|
||||
|
||||
subtest 'foo' => sub {
|
||||
my $items = [ Item->new( name => 'foo', sell_in => 0, quality => 0 ) ];
|
||||
my $app = GildedRose->new( items => $items );
|
||||
$app->update_quality();
|
||||
is( $app->{items}->[0]->{name}, 'fixme' );
|
||||
};
|
||||
|
||||
done_testing();
|
||||
Loading…
Reference in New Issue
Block a user