http://www.perlmonks.org?node_id=1059430

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

Morning Monks

This isn't really a detailed technical question, it's more a "accepted norm" query. As I have thought myself Perl without any immediate "go-to" person (there is nobody in my work environment that knows anything about coding!) I find I that I am struggling with coding practices and principles a lot.

I have recently moved from small (under 1000 lines) scripts to larger, modular, OOP projects. I won't lie, I am finding the concept a little difficult, especially coming from a non-coding background! Anyway, my question involves the creation of an instance and specifically how acceptable it is to modify it. Example:

Suppose this simple code:
#!/usr/bin/perl use strict; use warnings; use Storm; use Data::Dumper; my $config = { storm_server => '172.16.0.55', storm_port => '9001', storm_auth_login => '0', storm_login => '1', storm_user => 'stormuser', storm_pass => 'pass', }; my $self = Storm->new($config); print Dumper $self; package Storm; use IO::Socket; sub new { my $class = shift; my $self = shift; # The next lines, should this be here or in another # method if( $self->{storm_auth_login} ) { $self->{append_text} = "X12-" } bless $self, $class; return $self; }
As you can see I am creating an instance with a $config hash ref with certain information. However, is it the "norm / acceptable", as above, to check the argument and based on a value then modify it.
OR, is it better/normal to create a "blank" instance and then pass that into another method to change/modify?
OR, the third option: I am getting way to bogged down on what is the "norm" and I should worry more about my apparent lack of understanding of how OOP works!