Sha256: f64f822ededa28eb661bcff4140c49f55b1ae498a1fd967683e6e037aaaf43d2

Contents?: true

Size: 707 Bytes

Versions: 323

Compression:

Stored size: 707 Bytes

Contents

package Example;

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

323 entries across 323 versions & 1 rubygems

Version Path
trackler-2.2.1.105 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.104 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.103 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.102 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.101 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.100 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.99 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.98 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.97 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.96 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.95 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.94 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.93 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.92 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.91 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.90 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.89 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.88 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.87 tracks/perl5/exercises/space-age/Example.pm
trackler-2.2.1.86 tracks/perl5/exercises/space-age/Example.pm