Sha256: 40fc296693869c635562e8ada4430084fdb39a16439c37f827dd45a031c57e73

Contents?: true

Size: 708 Bytes

Versions: 73

Compression:

Stored size: 708 Bytes

Contents

package SpaceAge;

use strict;
use warnings;

my %orbital_period = qw(
    mercury 0.2408467
      venus 0.61519726
      earth 1
       mars 1.880818
    jupiter 11.862615
     saturn 29.447498
     uranus 84.016846
    neptune 164.79132
);

sub new {
    bless { seconds => $_[1] } => $_[0];
}

sub seconds { $_[0]->{seconds} }

sub _on_planet {
    my ($self, $planet) = @_;
    my $earth_years = $self->seconds / 31_557_600;

    return sprintf "%.2f" => ($earth_years / $orbital_period{$planet});
}

sub AUTOLOAD {
    my $sub = our $AUTOLOAD;
    $sub =~ s/.*::on_//;

    if ( grep { $_ eq $sub } keys %orbital_period ) {
        my $self = shift;
        return $self->_on_planet($sub);
    }
}

1;

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.138 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.137 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.136 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.135 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.134 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.133 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.132 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.131 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.130 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.129 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.128 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.127 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.126 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.125 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.124 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.123 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.122 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.121 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm
trackler-2.2.1.120 tracks/perl5/exercises/space-age/.meta/solutions/SpaceAge.pm