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.

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; }
I am getting this error:
Can't locate object method "heading" via package "main" at admin.pl line 152.

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'}; }


In reply to Object method in wrong namespace by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.