Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: PerlOO what i am doing???

by xyzzy (Pilgrim)
on Aug 12, 2012 at 01:23 UTC ( [id://986929]=note: print w/replies, xml ) Need Help??


in reply to PerlOO what i am doing???

What are you doing???

You have a constructor that doesn't do anything. Normally it would perform actions necessary to set up the object, for instance if your object was the database, the constructor might attempt to open a connection and store a handle to the database, as well as provide a mechanism for catching and reporting errors that occur.

You have a bunch of unfinished and unstarted methods. And then the methods that you do have are procedural and don't really fit with the OO paradigm.

Before you go any further, you should look up information about Object Oriented Programming, learn about abstraction, encapsulation, the difference between classes and objects, the relationship between objects and methods, etc. Then, only when you understand how OOP works, if you are working on a project that relies heavily on a database, I highly recommend DBIx::Class, a module that provides an object-oriented interface to a relational database (it is compatible with many backends, including MySQL). This will eliminate the need for SQL and it can generate classes with accessors and relationship mapping for all of your tables in a way that is intuitive and easy to understand. Right now your code, aside from being messy, wasteful, and mind-bogglingly obtuse, is vulnerable to SQL injection attacks (what will happen if I call $database->check_comment_record('1; drop table comment_record')?). Using DBIx::Class will solve these problems for you without you having to know anything about database security. Creating new records is as easy as

$schema->resultset('NewsPost')->create({ heading => "Llama thief still at large!", text => "Police are investigating leads but have refused to comment +on possible suspects...", photos => [{ img => 'llamas_01.png', caption => 'Five llamas have been confirmed missing since Tuesda +y (File photo)', },{ img => 'llamas_02.png', caption => 'Police Commissioner Turgidson, shown here making a p +ress statement Wednesday morning', }], url => '/news/llamas', })

You have a lot of reading to do before you can even try to do something like this. Wikipedia is an OK place to start. There are certain websites where you can obtain pdf copies of books about database programming. The CPAN documentation for DBI modules will be helpful if you sit down and read it very carefully. When you have enough of an idea about what you're doing to ask an actual question you can come back. The community here would be glad to help you, but only if you actually show us that you are someone who knows how to RTFM, use Google, and that you can figure basic things out on your own before asking for help with a specific issue or problem.


$,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
Happy, sober, smart: pick two.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://986929]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-24 01:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found