Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Perl Syntax - What's the difference?

by Galdor (Sexton)
on Apr 09, 2018 at 11:43 UTC ( #1212571=perlquestion: print w/replies, xml ) Need Help??

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

DBIC code used to work - using Moose, DBIC and DateTime (ymd(), and month_name()):
print $event->startdate->ymd(), " - ", $event->startdate->month_name() +;
and now the DB schema changed (underscore introduced in column names):
print $event->start_date->ymd(), " - ", $event->start_date->month_name +();
and now it does not:
Can't locate object method "ymd" via package "2008-08-18" (perhaps you + forgot to load "2008-08-18"?) at ./test-dbic-schema.pl line 50.
So what's the difference? Why should the underscore throw this out? What is the correct syntax/escaping for this stuff (Perl has kooki syntax sometimes)...

Replies are listed 'Best First'.
Re: Perl Syntax - What's the difference?
by Corion (Pope) on Apr 09, 2018 at 11:50 UTC

    Most likely this is because somewhere in your setup/configuration, there is something that tells Moose / DBIC / whatever to map values from a column startdate to DateTime objects. But now the column is named start_date and that list has not been adjusted appropriately.

    Alternatively, the column type has changed to something that the hidden magic of Moose / DBIC / whatever cannot determine that you want DateTime objects from what was a date column anymore. Or maybe it's now a timestamp column.

    Maybe reducing your zoo of modules to a simple case of one table with two columns, startdate and start_date that still fails to magically inflate one column but magically inflates the other column can help us to give you better advice.

      ok Corion - you da man! - Youre reponse pushed me in the right directions - for more investigations. Wow wasted an hour on that... It appears that the original scripts had this included:
      > __PACKAGE__->load_components( qw/InflateColumn::DateTime /);
      and newly generated ones not - it seems to be the way that the DBIC was generated from the Pg schema - there is a script (that I used) that does not add this "pacakge" and there are some notes in a readme to do:
      dbicdump -o components='["InflateColumn::DateTime"]' \
      so I guess that was it - not even in the source code! Who new?! Thanks once again for the steer..
Re: Perl Syntax - What's the difference?
by Your Mother (Bishop) on Apr 09, 2018 at 12:20 UTC

    Corion is right. It's not a Perl syntax issue, it's configuration.

    Probably it's one of two things. You regenerated your schema so you lost the custom code/config or you need to s/startdate/start_date/ in the inflation definition in your Result package matching the table that holds the column.

    You are either using DBIx::Class::InflateColumn::DateTime to inflate the column or doing it a bit more manually with DBIx::Class::InflateColumn; the second option seems more likely because the column name is repeated. Use the docs against your own .pm file and you should be able to fix it easily.

    Update: didn't see you'd worked it out before posting.

Re: Perl Syntax - What's the difference?
by LanX (Cardinal) on Apr 09, 2018 at 12:06 UTC
    > Can't locate object method "ymd" via package "2008-08-18"

    probably you have code where you use ymd without brackets?

    DB<4> $a="2008-08-18" DB<5> ymd $a Can't locate object method "ymd" via package "2008-08-18" (perhaps you + forgot to load "2008-08-18"?) at (eval 10)[/usr/share/perl/5.18/perl +5db.pl:732] line 2.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Wikisyntax for the Monastery

      There is no code (as posted) where ymd $foo is shown.

      The error message occurs for any string that gets used as a class/object without being blessed.

        The OP said the only thing he changed where "underscore introduced in column names" , so consequently I expected some side effects in code he is executing behind the scene.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1212571]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2020-11-25 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?