Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've 50 fairly simple classes similar to the one below. Unfortunately they have to be ported to an old machine and an old, static perl install. Does anyone know of a utility/script that will re-write my classes in the old pre-modern perl way?
package FailedFile; use Moose; has 'data' => ( is => 'rw', isa => 'Str' ); has 'file_failed' => ( is => 'rw', isa => 'Bool', default => '1' ); sub check_file { my $self = shift; blah; blah; $self->failed_file(1) if blah; } __PACKAGE__->meta->make_immutable; 1;

Replies are listed 'Best First'.
Re: Removing Moose
by Anonymous Monk on Oct 14, 2011 at 10:01 UTC

    LOL!

    What old perl version? Maybe you can use one of the Any::Mose like Mo

    Ok, here goes, use autodia to generate an UML file of your Moose classes

    Then use autodia.pl -t oldoo.tt ... to generate perl code from said UML file

    Generating from moose introspection might be faster /more accurate than going the autodia route

    Both options make me laugh :) upgrade upgrade upgrade upgrade upgrade :)

      > upgrade upgrade upgrade upgrade upgrade :)

      Can't its not my sandbox. Perl 5.6 FTW! As they say in kiddie world.

      Interesting link though. Thanks.

Re: Removing Moose
by doug (Pilgrim) on Oct 14, 2011 at 16:56 UTC

    Try something like

    sub data { my $self = shift; $self->{data} = "$_[0]" if ( @_ ); $self->{data}; } sub file_failed { my $self = shift; $self->{file_failed} = $_[0] ? 1 : 0 if ( @_ ); $self->{file_failed} || 0; }

    Note that you'll have to handle that default in the constructor (new() sub) yourself, although the  || 0 should cover most cases.

    - doug