Bod has asked for the wisdom of the Perl Monks concerning the following question:
Wise Monks,
I have been scratching my head for too long here...it is time to seek your wisdom. I suspect the problem is simple and sufficiently obvious that I shall kick myself when it is revealed!
I am developing a module for internal use that manipulates blog posts. It takes a hashref from a database, manipulates the data and can return either another hashref or any of the individual pieces of data. But it's not working so I have added some debug code. It is the behaviours of this debug code that I cannot understand.
I am getting this error:my $query = $dbh->prepare("SELECT * FROM Blog ORDER BY created DESC"); $query->execute; my $test; while( my $bg = $query->fetchrow_hashref ) { my $blog = Bod::Blog->new($bg) or die "Blog not defined"; $test = $blog->heading; # line 152 push @blogs, $blog->hashref; }
The heading method should be in the Bod::Blog namespace but the error suggests that Perl is looking for it in the main namespace. I cannot figure out why that might be!
Here is the first part of Blog.pm...
package Bod::Blog; use strict; use warnings; sub new { my ($class, $blog, $vars); $vars->{'heading_class'} ||= 'blogHead'; $vars->{'subheading_class'} ||= 'blogSubHead'; $vars->{'body_class'} ||= 'blogBody'; $vars->{'base_path'} ||= '/blog/'; $vars->{'image_path'} ||= '/images/blog/'; my $self = bless { 'blog' => $blog, 'vars' => $vars, }, $class; return $self; } sub heading { my $self = shift; return $self->{'heading'}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Object method in wrong namespace
by LanX (Saint) on Feb 27, 2022 at 20:42 UTC | |
by Bod (Parson) on Feb 28, 2022 at 23:39 UTC | |
by LanX (Saint) on Mar 01, 2022 at 00:41 UTC |