[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] (QXP => HTML) && OOP



Thanks to everyone who responded so promptly to my message.  This is the
first time I've ever tried to create my own objects, methods and classes,
so it has taken me a while to (partly) digest all of the material...

On Fri, Mar 28, 1997 4:58 AM, Fred Fenimore wrote: 
>>I did do an identical project recently and found using multi-dimensional
>>hashes worked pretty well.
>>
>>%ssdef{"Body_Text"}{SIZE} = 12;
>>%ssdef{"Body_Text"}{FONT} = "Times";
>>
>>and so on...
>>
>>This might be one of those cases where the tool debate comes up...

In case the OOP methods people have suggested here don't work, I'll be
using your multi-dimensional hashes.

The reason I'm trying to use objects in this program is that I find it a
lot easier to conceptualize what I'm doing that way -- and the easier it is
to think about what I'm doing, the easier (by a _long_ shot) I find it to
design and code it.

This also seemed like a good pilot project for learning how to create my
own objects, which I've never done before.

>>BTW (off the subject) [Stuff about QXP and tags quoted below]

Not at all!  That's partly why I raised this problem here instead of on the
newsgroup.  More on this at the end of the post, after the problem at hand
is examined at greater length.

On Fri, Mar 28, 1997 5:46 AM, Paul J. Schinder wrote: 
>>I assume you can do
>>something like this if you have a list of names
>>
>>foreach $name (@names) {
>>	${$name} = new Style_Sheet($name,12,$font);
>>}
>>
>>but of course you should try it and see to make sure.  Alternatively, you
>>could always make a hash of references to the sheets:
>>
>>foreach $name (@names) {
>>	$Sheets{$name} = new...
>>}
>>

The first thing I had to do was turn off "use strict" in order to even get
my code to compile with these approaches.  Having done that, however, the
scalar approach didn't work at all.

The hash approach worked fine for creating the objects.  But as Chris
Nandor pointed out, the last hash element used to name an object carries
the blessing with it, so if you create style sheet A, you can use values
from it using the hash element as a key.

But if you then create style sheet B, from that point on, $Sheets{$name}
refers to style sheet B, even if you set $name to A. :(

On Fri, Mar 28, 1997 6:25 AM, Joe McMahon wrote: 
>>Wrap the storage mechanism up in an object.
>>
>>package SSLib;
>>  sub new {
>>      my $class = shift;
>>      my $self = {};
>>      bless $self,$class;
>>  }
>>
>>  sub add {
>>      my $class = shift;
>>      my ($sheetName,$sheetRef) = shift;
>>      my %zorch = $self->{LibHash};
>>      my old = $zorch{$sheetName};
>>      $zorch{$sheetName} = $sheetRef;
>>      $self->{LibHash} = %zorch;
>>      return $old;
>>  }
>>  sub del {
>>      my ($class, $sheetName) = @_;
>>      my %zorch = $self->{LibHash};
>>      my $old = $zorch{$sheetName};
>>      delete $zorch{$sheetName};
>>      return $old;
>>  }
>>  sub fetch {
>>      my ($class,$sheetName} = @_;
>>      my %zorch = $self->{$LibHash};
>>      return $zorch{$sheetName};
>>  }
>>

This sounds very promising, but as I said above, I'm pretty new to this, so
I'm still kind of confused.  Here are the main questions I'm unclear on:

1. Is the "add" method used instead of the "new" method when I want to
create a new object?

2. Is $LibHash (I think it's $LibHash, as opposed to LibHash, no?) local to
the whole package (I think so)?

3. I'm getting a bit mixed up because of the $self variables in each method
(subroutine).  What is $self->{$LibHash} really doing here?

4. Why does the return statement override the blessing?

I'd be really grateful if somebody can clear these up for me.  I know they
are very basic questions, and in some ways this code is quite simple, but
there is a certain leap required to understanding why this works so
"magically", and I haven't yet made that leap.

On Fri, Mar 28, 1997 4:58 AM, Fred Fenimore wrote: 
>>Did you write the xtags parser yourself?  What approach did you take?  I
>>did it by slurping the file into one long string then used about 2 dozen
>>global search replace statemnts to seperate the tags.  Then I used even
>>more s//mg's to convert it to my final format.

I'm just getting started on the project, and haven't even fully thought it
through.  I'll probably break out the style sheets first (in one long
slurp, as you did), and may then make several passes on the data to figure
out which HTML paragraph tag should be applied to each paragraph.  Then
I'll style the bolds, etc.

I'm using Xtags 2.0, which lets you output text with individual tags (e.g.,
"<B><I>", etc.), so I won't need to separate them in my program.  Xtags is
a _great_ XTension (for that and many other reasons)!

>>Of course we had to go to pretty great lengths to "fix" text that had the
>>wrong style sheet applied, e.g. text set in headline format which then
they
>>change the font, size, face to match what normally would be body text.

Part of the reason I like the object approach is that it makes it easier
for me to think about the meat and potatoes work of doing this kind of
processing.  (I recently worked on the second edition of a textbook where
the _whole_ book was formatted with a single style sheet to which the
person who set the first edition made manual changes for virtually every
paragraph in the 600-page book -- so I know what you're talking about
here!)

>>Ran into problems with the
>>tags that contain quoted material though...

I was worried about numbered lists, but hadn't thought about problems with
quoted material -- why was this a problem?


Thanks,
Richard

__________________________
Richard Pfeiffer <pfeiffer@well.com>
Publishing Automation/Database Consulting/Book Production
BMUG Scripting SIG -- Next Meeting:
Monday 4/21/97, BMUG offices @ 6:00 p.m.