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

This is an attribute which belongs to a class that inherits from Moo
has '_print' => ( is => 'ro', default => sub { Slic3r::Print->new }, handles => [qw(apply_config extruders expanded_output_fil +epath total_used_filament total_extruded_volume placeholder_parser process)], );
This is the code for Slic3r::Print->new
sub new { # TODO: port PlaceholderParser methods to C++, then its own constr +uctor # can call them and no need for this new() method at all my ($class) = @_; my $self = $class->_new; $self->placeholder_parser->apply_env_variables; $self->placeholder_parser->update_timestamp; return $self; }
1. _print doesn't pass any parameters, so what is $class supposed to be assigned? I'm guessing the object which calls the method? 2. _new, haven't been able to find the relevant code for this subroutine. If Simple inherits from Moo::Object then it's in a file with package Moo::Object, right? Or is there some other possibility? 3. placeholder_parser. There is no placeholder_parser subroutine definition in the entire directory for the program or the Perl library. So, what exactly is it doing? Also, if self refers to the Simple object, then how is it calling the delegate before Print->new has returned a value? Thanks

Replies are listed 'Best First'.
Re: I don't understand this code, perl delegates and empty parameter lists.
by marto (Cardinal) on Mar 20, 2015 at 09:18 UTC

    "3. placeholder_parser. There is no placeholder_parser subroutine definition in the entire directory for the program or the Perl library. So, what exactly is it doing?"

    A quick search shows this among the results:

    has 'placeholder_parser' => (is => 'rw', default => sub { Slic3r::GCod +e::PlaceholderParser->new });
      Oh okay, that makes sense.
Re: I don't understand this code, perl delegates and empty parameter lists.
by Anonymous Monk on Mar 20, 2015 at 09:09 UTC

    1. _print doesn't pass any parameters, so what is $class supposed to be assigned?

    When you add "print @_" what gets printed?

    Have you read perlobj?

      So then what is _new calling? Print doesn't seem to inherit any classes. Here is the code

      https://github.com/alexrj/Slic3r/blob/master/lib/Slic3r/Print.pm

Re: I don't understand this code, perl delegates and empty parameter lists.
by Anonymous Monk on Mar 20, 2015 at 09:12 UTC

    There is no placeholder_parser subroutine definition in the entire directory for the program or the Perl library. So, what exactly is it doing?

    What file where (got link/url)?

      https://github.com/alexrj/Slic3r
Re: I don't understand this code, perl delegates and empty parameter lists.
by Anonymous Monk on Mar 20, 2015 at 09:08 UTC
    A class that inherits from Moo? Weird
      >A class that inherits from Moo? Weird well it uses Moo, so it inherits from Moo:Object right? btw how do I make newlines on this forum?

        Welcome, this explains the basics of formatting and post conventions.

        well it uses Moo, so it inherits from Moo:Object right?

        Well, pretend that Moo::Object doesn't exist :) thats stuff for Moo.pm not you and me:)