Changeset 29677

Show
Ignore:
Timestamp:
09.01.2015 13:33:16 (4 years ago)
Author:
jts21
Message:

Splitting up site module to allow creating sibling interface module

Location:
main/trunk/package-kits/scripts/perllib/Greenstone
Files:
2 added
1 modified
1 moved

Legend:

Unmodified
Added
Removed
  • main/trunk/package-kits/scripts/perllib/Greenstone/Site.pm

    r29676 r29677  
    44use warnings; 
    55use utf8; 
    6 use base 'Exporter'; 
    7  
    8 use Greenstone::Config; 
    9 use XML::Tidy; 
    10  
    11 our $VERSION = 1.00; 
    12 our @EXPORT = ( ); 
     6use Greenstone::Directory; 
     7use Greenstone::XML::Tidy; 
     8use parent 'Greenstone::Directory'; 
     9 
     10my $dir = "sites"; 
     11 
     12sub new { 
     13    return Greenstone::Directory::new ($dir, @_); 
     14} 
     15 
     16sub list { 
     17    return Greenstone::Directory::list $dir; 
     18} 
     19 
    1320my $configTemplate; 
    14  
    15 sub new { 
    16     my ($class, $name, %args) = @_; 
    17     ref $class and die "Constructor used as object method\n"; 
    18     defined $name or die "A site must have a name\n"; 
    19     my $self = bless ( 
    20         { 
    21             name => $name, 
    22         }, 
    23         $class 
    24     ); 
    25     for my $param (keys %args) { 
    26         $self->{$param} = $args{$param}; 
    27     } 
    28     return $self; 
    29 } 
    30  
    31 sub list { 
    32     ref shift and die "Static method called on object\n"; 
    33     my $sites = {}; 
    34     my $dir = "$Greenstone::Config::GSDL3HOME/sites"; 
    35     opendir DH, $dir or die "Could not open sites directory '$dir'\n"; 
    36     while (my $site = readdir DH) { 
    37         # skip hidden files and current/parent directory 
    38         $site =~ /^\./ and next; 
    39         # skip non-directories 
    40         -d "$dir/$site" or next; 
    41         # We don't really need to store anything more than the fact that the site exists 
    42         # So we just store nothing, which is enough to put the key in the hash 
    43         # (i.e. it acts as a hashset) 
    44         $sites->{$site} = (); 
    45     } 
    46     closedir DH; 
    47     return $sites; 
    48 } 
    49  
    50 sub exists { 
    51     my $self = shift; 
    52     my $sites = list; 
    53     return exists $sites->{$self->{name}}; 
    54 } 
    5521 
    5622sub create { 
    5723    my $self = shift; 
    58     $self->exists and return 0; 
    59     my $dir = "$Greenstone::Config::GSDL3HOME/sites/$self->{name}"; 
    60     mkdir $dir or die "Failed to create site directory: $!\n"; 
     24    $self->SUPER::create or return 0; 
     25    my $dir = $self->dir; 
    6126    mkdir "$dir/collect" or die "Failed to create collections directory: $!\n"; 
    6227    open FH, '>', "$dir/siteConfig.xml" or die "Failed to create site config: $!\n"; 
     
    497462}; 
    498463 
     4641; 
  • main/trunk/package-kits/scripts/perllib/Greenstone/XML/Tidy.pm

    r29673 r29677  
    1 package XML::Tidy; 
     1package Greenstone::XML::Tidy; 
    22 
    33use strict;