Skip to content

Commit

Permalink
Add Perl6 version
Browse files Browse the repository at this point in the history
  • Loading branch information
cono committed Jul 14, 2017
1 parent de471eb commit a5309b3
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/workspace.xml
*.pyc
/perl6/lib/.precomp
66 changes: 66 additions & 0 deletions perl6/lib/GildedRose.pm6
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use v6;

use Item;

class GildedRose {
has Item @.items;

method update_quality {
for @!items -> $item {
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;
}
};
11 changes: 11 additions & 0 deletions perl6/lib/Item.pm6
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use v6;

class Item {
has Str $.name;
has Int $.sell_in is rw = 0;
has Int $.quality is rw = 0;

method Str {
"{$!name}, {$!sell_in}, {$!quality}"
}
};
16 changes: 16 additions & 0 deletions perl6/test.p6
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env perl6

use v6;
use Test;
use lib 'lib';

use GildedRose;
use Item;

my $item = Item.new(:name<foo>);
my $app = GildedRose.new(items => ($item));

$app.update_quality();
is $app.items[0].name, 'fixme', "first day pass";

done-testing;
70 changes: 70 additions & 0 deletions perl6/texttest_fixture.p6
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env perl6

use v6;

use lib 'lib';

use GildedRose;
use Item;

print 'OMGHAI!', "\n";
my @items = (
Item.new(
name => '+5 Dexterity Vest',
sell_in => 10,
quality => 20
),
Item.new(
name => 'Aged Brie',
sell_in => 2,
quality => 0
),
Item.new(
name => 'Elixir of the Mongoose',
sell_in => 5,
quality => 7
),
Item.new(
name => 'Sulfuras, Hand of Ragnaros',
sell_in => 0,
quality => 80
),
Item.new(
name => 'Sulfuras, Hand of Ragnaros',
sell_in => -1,
quality => 80
),
Item.new(
name => 'Backstage passes to a TAFKAL80ETC concert',
sell_in => 15,
quality => 20
),
Item.new(
name => 'Backstage passes to a TAFKAL80ETC concert',
sell_in => 10,
quality => 49
),
Item.new(
name => 'Backstage passes to a TAFKAL80ETC concert',
sell_in => 5,
quality => 49
),
Item.new( # This Conjured item does not work properly yet
name => 'Conjured Mana Cake',
sell_in => 3,
quality => 6
),
);

sub MAIN(Int $days = 2) {
my $gilded-rose = GildedRose.new( items => @items );
for ^$days -> $day {
say "-------- day $day --------";
say 'name, sellIn, quality';

.Str.say for $gilded-rose.items;

"".say;
$gilded-rose.update_quality();
}
}

0 comments on commit a5309b3

Please sign in to comment.