+my $term = new Term::ReadLine "Edit Title";
+
+FsObj->new(getcwd)->iterate;
+if ($feedobj) {
+ $feedobj->{-feed}->pubDate(time);
+ $feedobj->{-feed}->to_file($feedobj->{-savepath});
+}
+
+sub help {
+
+ print STDERR <<__END__;
+usage: $0 [options]
+ --help: print help message and exit
+ --incpath: do not try to find .gallery2 directory upstream, use
+ specified path (absolute or relavive). Use with causion.
+ --debug: print a lot of debugging info to stdout as you run
+ --asktitle: ask to edit album titles even if there are ".title" files
+ --noasktitle: don't ask to enter album titles even where ".title"
+ files are absent. Use partial directory names as titles.
+ --feed=...: build Atom feed for newly added "albums",
+ enter filename, base URL, and optionally PuSH hub url,
+ separated by commas. (Note: PuSH obviously does not work
+ "out of the box" for static tree! You need a separate
+ "watcher" script to do the publishing for you.)
+__END__
+
+ exit 1;
+}
+
+sub new {
+ my $this = shift;
+ my $class;
+ my $self;
+ if (ref($this)) {
+ $class = ref($this);
+ my $parent = $this;
+ my $name = shift;
+ $self = {
+ -parent=>$parent,
+ -root=>$parent->{-root},
+ -toppath=>$parent->{-toppath},
+ -depth=>$parent->{-depth}+1,
+ -base=>$name,
+ -fullpath=>$parent->{-fullpath}.'/'.$name,
+ -relpath=>$parent->{-relpath}.$name.'/',
+ -inc=>'../'.$parent->{-inc},
+ };
+ } else {
+ $class = $this;
+ my $root=shift;
+ $self = {
+ -root=>$root,
+ -fullpath=>$root,
+ };
+ # fill in -inc, -feed, -relpath
+ initpaths($self); # we are not blessed yet, so cheat.
+ }
+ bless $self, $class;
+ if ($debug) {
+ print "new $class:\n";
+ foreach my $k(keys %$self) {
+ print "\t$k\t=\t$self->{$k}\n";
+ }
+ }
+ return $self;
+}
+
+sub initpaths {
+ my $self=shift; # this is not a method but we cheat
+ my $depth=20; # arbitrary max depth
+ my $fullpath=$self->{-fullpath};
+ my $inc;
+ my $relpath;
+
+ if ($incpath) {
+ $inc = $incpath;
+ $inc .= '/' unless ($inc =~ m%/$%);
+ } else {
+ $inc="";
+ while ( ! -d $fullpath."/".$inc."/".$incdir ) {
+ $inc = "../".$inc;
+ last unless ($depth-- > 0);
+ }
+ }
+ if ($depth > 0) {
+ $self->{-inc} = $inc;
+ my $dp=0;
+ my $pos;
+ for ($pos=index($inc,'/');$pos>=0;
+ $pos=index($inc,'/',$pos+1)) {
+ $dp++;
+ }
+ $self->{-depth} = $dp;
+ for ($pos=length($fullpath);$dp>0 && $pos>0;
+ $pos=rindex($fullpath,'/',$pos-1)) {
+ $dp--;
+ }
+ my $relpath = substr($fullpath,$pos);
+ $relpath =~ s%^/%%;
+ $relpath .= '/' if ($relpath);
+ $self->{-relpath} = $relpath;
+ $self->{-toppath} = substr($fullpath,0,$pos);
+ #print "rel=$relpath, top=$self->{-toppath}, inc=$inc\n";
+ initfeed($self);
+ } else {
+ $self->{-inc} = 'NO-.INCLUDE-IN-PATH/'; # won't work anyway
+ $self->{-feed} = '';
+ $self->{-relpath} = '';
+ $self->{-depth} = 0;
+ }
+}
+
+sub initfeed {
+ my $self=shift; # this is not a method but we cheat
+ my $fullpath=$self->{-fullpath};
+ my $toppath=$self->{-toppath};
+ my $inc=$self->{-inc}.$incdir.'/';
+ my $conffile=$toppath.'/'.$incdir.'/feed.conf';
+ my $CONF;
+
+ if (! $incpath) {
+ if ($feed) {
+ if (open($CONF,">".$conffile)) {
+ print $CONF $feed,"\n";
+ close($CONF);
+ } else {
+ print STDERR "could not open $conffile: $!\n";
+ }
+ } else {
+ if (open($CONF,$conffile)) {
+ $feed=<$CONF>;
+ close($CONF);
+ chop $feed;
+ }
+ }
+ }
+
+ return unless ($feed);
+
+ my ($feedfile, $feedbase, $feedhub) = split(',', $feed);
+ $feedbase .= '/' unless ($feedbase =~ /\/$/);
+ print "($feedfile, $feedbase, $feedhub)\n";
+
+ $feedobj->{-savepath} = $self->{-toppath}.'/'.$feedfile;
+ $feedobj->{-file} = $feedfile;
+ $feedobj->{-base} = $feedbase;
+ $feedobj->{-hub} = $feedhub;
+ if ( -f $feedobj->{-file} ) {
+ $feedobj->{-feed} = XML::FeedPP::Atom::Atom10->new(
+ $feedobj->{-file});
+ $feedobj->{-feed}->limit_item(15);
+ } else {
+ $feedobj->{-feed} = XML::FeedPP::Atom::Atom10->new;
+ $feedobj->{-feed}->title("Gallery");
+ $feedobj->{-feed}->description("generated by ".
+ "<a href=\"http://www.average.org/mkgallery/\">".
+ "mkgallery</a>");
+ $feedobj->{-feed}->link($feedbase);
+ #$feedobj->{-feed}->copyright("");
+ #$feedobj->{-feed}->language("en");
+ #$feedobj->{-feed}->image($url, $tit, $link, $desc, $w, $h);