Log in

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

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

[Apr. 14th, 2004|01:40 pm]
LiveJournal Client Discussions


[mood |accomplishedaccomplished]

Just released version 0.11 of LJ::Simple; this release has two changes:

  • The test harness has been adjusted for the test username being removed from the LiveJournal servers due to abuse. The test.pl script has been built so that if you use the test username (which you can still log in as) then it will use a small sub-set of the tests. However if you provide it with a different username and password the entire test suite will be used. I'm not going to guarentee that the test.pl script won't do unpleasant things to the LJ you do point it at

  • The DefaultPicURL() routine has been added which returns the URL of the default icon for the logged in user.

[User Picture]From: halkeye
2004-04-16 10:27 pm (UTC)
my @data = $lj->PostEntry($event) || undef;
my ($item_id,$anum,$html_id) = @data;
die Dumper(@data);

$VAR1 = 20841;

thats the anum (http://www.livejournal.com/users/halkeyedotnet/20841.html)

Has something major changed?
(Reply) (Thread)
[User Picture]From: simonb
2004-04-17 09:06 am (UTC)

Nope; it works fine if you call it correctly. Take off the || undef and everything works as expected Personally I prefer to call PostEntry() in the following way:

my ($item_id,$anum,$html_id)=$lj->PostEntry($event);
(defined $item_id) || die "$0: Failed to post entry - $LJ::Simple::error\n";

The above being basically what is shown in the example bit of code for PostEntry() within the LJ::Simple documentation.

(Reply) (Parent) (Thread)
[User Picture]From: fantasylite
2004-04-30 10:46 am (UTC)
Have you considered porting this package to use Net::HTTP::NB for aplications where blocking on calls to the net is undesireable? (for example when also using pTk)
(Reply) (Thread)
[User Picture]From: simonb
2004-04-30 07:16 pm (UTC)
I'd prefer to not do this; right now LJ::Simple doesn't require anything outside of the standard perl installation from 5.6.1 onwards thanks to it only using Socket. If I was to port it to use Net::HTTP::NB it would have to keep this feature as I know that some of the people using LJ::Simple prefer this. Thus I'd have to write it in such a way that if Net::HTTP::NB was available then it would be used... and I'd also have to code that up from scratch since LJ::Simple doesn't use Net::HTTP anyway.

I should probably note that LJ::Simple already uses select() calls when reading results from the LiveJournal server, with the $LJ::Simple::timeout value being passed directly into the select() timeout call.
(Reply) (Parent) (Thread)
[User Picture]From: fantasylite
2004-05-01 11:34 am (UTC)

In that case, will you mind terribly if I use your code as a reference point when I build my own?

Even with timeouts, I prefer my HTTP calls to be non-blocking. (a ten second time out, in a TK gui, means that your program just appeared to freeze for ten seconds. And that is not good. Or else I have to deal with forking and IPC under windows, which is a pain. I've done it before, but it is a pain.)
(Reply) (Parent) (Thread)
[User Picture]From: simonb
2004-05-02 06:32 am (UTC)

I don't mind if you use my code as a base so long as you give credit - its under a BSD license.

I can understand wanting the HTTP work to be done in a non-blocking manner, or at least in a way in which you can insert calls into the stuff.

Hmmmm.... what I could do is make a small alteration to the module to allow you to get around this. How about something where I add a mode to just use select() to see if data is ready or not (ie timeout is 0) and have it call a user defined sub-routine if its not finished reading data ? In that way you could insert the TK equivalent of processing all GUI events in the queue into the reading of the HTTP data... and allow me to keep the current interface to the module as it is right now. There would be some faffing around in the module to manually keep track of timeouts, but that shouldn't be too hard to do.

The only change to the interface would be for you to set the sub-routine reference you wanted into a module variable, i.e. something like:


I'd probably work something in as well so that the sub-routine called would be given details on the status of the request as well.

Would that be suitable ?

(Reply) (Parent) (Thread)
[User Picture]From: fantasylite
2004-05-02 11:38 am (UTC)
If you could do that, it would be very helpful.

(Reply) (Parent) (Thread)
[User Picture]From: simonb
2004-05-02 02:41 pm (UTC)

Okay, just put something together which seems to work quite well. The only point it could really block is within the name resolution of inet_aton(), although you could give the module an IP address you have previously resolved to get around that. The documentation from the module for this is:


By default this is set to undef. When given a reference to a sub-routine this module will call the given sub-routine at various stages of processing the responses to the LiveJournal server. This is intended for GUI applications which need to process event queues, update progress bars, etc. When called the sub-routine is passed a number of variables which maybe useful; the calling method is:


  $mode      - The mode sent to the LJ server
  $status    - The status of the request; ranges from 0 to 1
  $action    - The action performed
  $bytes_in  - The number of bytes read from the remote server
  $bytes_out - The number of bytes written to the remote server
  $time      - The time taken so far in seconds
  $waiting   - Are we waiting for a response from the server ?

It should be noted that if $waiting is set to 1 then it is highly recommended that the sub-routine calls select() itself to provide at least some time delay. If this is not done it is likely that this module will consume far more CPU than necessary.

An example sub-routine follows:

sub LJStatus {
  my ($mode,$status,$action,$bytes_in,$bytes_out,$time,$waiting) = @_;
  print "\$mode      = $mode\n";
  print "\$status    = $status\n";
  print "\$action    = $action\n";
  print "\$bytes_in  = $bytes_in\n";
  print "\$bytes_out = $bytes_out\n";
  print "\$time      = $time\n";
  print "\$waiting   = $waiting\n";
  print "\n";
  ($waiting) && select(undef,undef,undef,0.5);


I also added the $LJ::Simple::ProtoSub which allows you to show the LiveJournal protocol more easily within a GUI client; docs for that are:


By default this points to a sub-routine within the module; this is called when the protocol between the module and LiveJournal server is to be shown, in other words when $LJ::Simple::protocol is set to 1. The sub-routine called must take two variables; it is called in the following way:


  $direction - The direction of the flow; 0 means from client to server
               and 1 means from server to client
  $data      - The data which has flowed; there should not be any newlines
               with the data, but do not rely on this.
  $server    - The name of the LJ server we are talking to
  $ip_addr   - The IP address of the LJ server we are talking to

If both variables are undef then data is about to flow. If just $direction is undef then $data holds an informational message.

The standard sub-routine which is called is:

sub DefaultProtoSub {
  my ($direct,$data,$server,$ip_addr)=@_;
  my $arrow="--> ";
  if (!defined $direct) {
    if (!defined $data) {
      print STDERR "Connecting to $server [$ip_addr]\n";
      print STDERR "Lines starting with \"-->\" is data SENT to the server\n";
      print STDERR "Lines starting with \"<--\" is data RECEIVED from the server\n";
  } else {
    ($direct) && ($arrow="<-- ");
  print STDERR "$arrow$data\n";

I've made an alpha of 0.12 for you; its available from http://www.bpfh.net/other/LJ-Simple-0.12-ALPHA.tar.gz

Could you test this and let me know if it meets your needs; if it does I'll make it an offical 0.12 release.

(Reply) (Parent) (Thread)
[User Picture]From: fantasylite
2004-05-02 07:31 pm (UTC)
Thanks! I probably won't be able to test it throughly before tuesday, but I'll let you know as soon as I can.
(Reply) (Parent) (Thread)
[User Picture]From: simonb
2004-05-10 02:28 pm (UTC)
Any luck with the changes I made ?
(Reply) (Parent) (Thread)