?

Log in

No account? Create an account
LiveJournal.pm - LiveJournal Client Discussions [entries|archive|friends|userinfo]
LiveJournal Client Discussions

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

LiveJournal.pm [Nov. 4th, 2003|11:11 pm]
LiveJournal Client Discussions

lj_clients

[coderlemming]
I'm writing a little PERL script that'll let me copy entries between two LiveJournal-based sites periodically (I have my reasons). I discovered LiveJournal.pm -- how neat. However, I am deeply irked by the way it's coded. Naturally my instinct is to call LiveJournal->new twice, to create two $lj objects, one for the "from" server and one for the "to" server. Unfortunately, although LiveJournal.pm pretends to be coded using PERL object-orientation, the variables like username and password are global to all objects. I'm going to recode it, but in the meantime, has anyone dealt with this problem, and have they already fixed the code?
linkReply

Comments:
[User Picture]From: archon
2003-11-04 10:37 pm (UTC)
are you talking about the LiveJournal.pm that i wrote? if so, i don't believe that is the case (global user/pass).
(Reply) (Thread)
[User Picture]From: coderlemming
2003-11-05 10:31 am (UTC)
Whoops, I made the incorrect assumption that this was an officially LiveJournal sanctioned module. Doh.

Anyway, I have version 1.3 of LiveJournal.pm written by you. LiveJournal::Journal and LiveJournal::Friend inherit from LiveJournal directly, and LiveJournal's new function is declared inside a block with a few "my" variables. When it creates a new object to return, it populates it with references to those variables -- essentially making those variables global to all LiveJournal (and LiveJournal::Friend, LiveJournal::Journal) objects.
(Reply) (Parent) (Thread)
[User Picture]From: archon
2003-11-05 11:16 am (UTC)
ah, i see. this was done on purpose for convenience. i didn't forsee the need to create two instances. i can see why that would cause an issue in your case. i haven't really looked at the module in over a year, but looking through it now i believe modifying it to your preferred behavior is non-trivial. i'd suggest using another module if you're in a hurry. otherwise, patches welcome. (=
(Reply) (Parent) (Thread)
[User Picture]From: coderlemming
2003-11-05 03:01 pm (UTC)
No, actually, it was pretty trivial, though somewhat of a hack. I could have made it so that the instance variables weren't references, but that would have meant changing every usage. Instead I just brought the "my" declarations into the new sub itself, so that they were unique to each object. Then I made a "new" sub in the Journal and Friend packages, which would take a LiveJournal object and blatantly rip off its member variables. Not necessarily very OO-happy either, but it worked, and it was quick. I'll send over a patch when I get home tomorrow.
(Reply) (Parent) (Thread)
[User Picture]From: simonb
2003-11-04 11:32 pm (UTC)
There is always LJ::Simple
(Reply) (Thread)
[User Picture]From: coderlemming
2003-11-05 10:31 am (UTC)
Where do I get that?
(Reply) (Parent) (Thread)
[User Picture]From: simonb
2003-11-05 12:27 pm (UTC)
Its available from CPAN or from this site
(Reply) (Parent) (Thread)
[User Picture]From: alexmc
2003-11-05 02:21 am (UTC)
Always try to talk to the author of any perl module which you wish to enhance. They may be working n improvements, and appreciate a patch, or they may be looking for someone else to look after the software in its entirety.

PS Is this a CPAN module?
(Reply) (Thread)
[User Picture]From: coderlemming
2003-11-05 10:32 am (UTC)
Whoops, I made the foolish assumption that it was an official LiveJournal-sanctioned module.

I got it from searching for "LiveJournal perl" in google, it's the first hit. I don't think it's in CPAN.
(Reply) (Parent) (Thread)