Sha256: fdcf3f57cec0da65181f2c64e0ae36be5b436e84826c4e95c05f8bed8581e353

Contents?: true

Size: 692 Bytes

Versions: 75

Compression:

Stored size: 692 Bytes

Contents

use v6;

class X::Phone::Invalid is Exception {
  has $.payload;
  method message {"'$!payload' is not valid."}
}

class Phone is export {
  has $.number;

  method new (:$number!) {
    my $validated = $number;
    $validated ~~ s:g/<:!Decimal_Number>//;
    $validated ~~ /^ 1? (\d ** 10) $/ ?? ($validated = ~$0) !! X::Phone::Invalid.new(payload => $number).throw;
    self.bless(number => $validated);
  }

  method area-code {
    $!number ~~ /\d**3/ and return ~$/;
  }

  method pretty {
    $!number ~~ /
      $<area-code> = \d**3
      $<central-office-code> = \d**3
      $<station-number> = \d**4
    / and return "($<area-code>) $<central-office-code>-$<station-number>";
  }
}

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
trackler-2.0.8.28 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.27 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.26 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.24 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.23 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.22 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.21 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.20 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.19 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.18 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.17 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.16 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.15 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.14 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.13 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.12 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.11 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.10 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.9 tracks/perl6/exercises/phone-number/Example.pm
trackler-2.0.8.8 tracks/perl6/exercises/phone-number/Example.pm