Sha256: a74f20954b757b20252ecec483c5fdc29487e484ab767d5c6d0bc23d2ca56fa6

Contents?: true

Size: 658 Bytes

Versions: 323

Compression:

Stored size: 658 Bytes

Contents

package Example;

use strict;
use warnings;

sub new {
    my $class = shift;
    bless {data => shift, next => shift}, $class;
}

sub next :method { $_[0]->{next} }
sub data         { $_[0]->{data} }

sub from_array {
    my( $pkg, $array ) = @_;

    my $head;
    map { $head = __PACKAGE__->new($_, $head) } reverse @$array;
    return $head;
}

sub to_array {
    my $self = shift;
    
    my @array;
    do { push @array, $self->data() } while( $self = $self->next() );
    return \@array;
}

sub reverse :method {
    my $self = shift;

    my $array = $self->to_array();
    @$array = reverse @$array;

    __PACKAGE__->from_array( $array  );
}

1;

Version data entries

323 entries across 323 versions & 1 rubygems

Version Path
trackler-2.2.1.65 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.64 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.63 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.62 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.61 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.60 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.59 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.58 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.57 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.56 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.55 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.54 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.53 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.52 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.51 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.50 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.49 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.48 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.47 tracks/perl5/exercises/simple-linked-list/Example.pm
trackler-2.2.1.46 tracks/perl5/exercises/simple-linked-list/Example.pm