use v5.14; use warnings; use DBI (); package MyApp { use Class::Tiny qw( version dbh output_file ); sub do_something { my $self = shift; if ( $self->version < 1.0 ) { # an object attribute $self->do_something_simple; } else { $self->do_something_complex; } } sub do_something_simple { my $self = shift; open my $fh, '>', $self->output_file or die; print $fh "Hello world\n"; close $fh; } sub do_something_complex { my $self = shift; open my $fh, '>', $self->output_file or die; print $fh "Hello world\n"; printf $fh "There are %d rows in the table.\n", $self->dbh->do("SELECT 1 FROM my_table"); close $fh; } } my $app = MyApp->new( version => 1.2, dbh => DBI->connect("dbi:SQLite:dbname=myapp.sqlite"), output_file => '/tmp/output.txt', ); $app->do_something;