Hello i need some help understanding OOP Perl using Moose; i have created a class whose attributes are all subtypes , for validation purposes. Example code :
package InputData; use Moose; use InputDataSubtypes qw(subtype); has 'attribute' => ( is => 'rw', isa => subtype, required => 1, ); 1;
I want to pass InputData to a subroutine , then use InputData->attribute , as if i would be using a getter in Java. The InputData->attribute is used to do a query on a mysql database using prepared statement:
package Operations; use DBI; use DBConnection; use InputData; use Moose; sub querryDatabase() { my($inputData) = @_; my $query = 'select stuff from myTable where attribute = ?'; my $dataSource = DBConnection->getConnection(); my $preparedStatement = $dataSource->prepare($query); $preparedStatement->execute($inputData->attribute) or die "SQL Erro +r: $DBI::errstr\n"; while (my @row = $preparedStatement->fetchrow_array){ print "@row\n +"; } $preparedStatement->finish(); $dataSource->disconnect(); } 1;
i call the subroutine like this :
package MainScript; use strict; use warnings; use v5.22; use InputData; use Operations; use Moose; my $myInputData = InputData->new( { attribute => 'caller', } ); #here i do the sub call; Operations->querryDatabase($myInputData);
But i get the error Can't locate object method "attribute" via package "Operations" at ....Operations.pm line 28. Any help would be greatly appreciated, also sorry if i didn't format the question appropiatly
In reply to calling sub with object as param by perlnewb4life
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |