Krang::Site - a means to access information on sites


  use Krang::ClassLoader 'Site';
  # construct object
  my $site = Krang::Site->new(preview_url => '',   # required
                              preview_path => 'preview/path/',# required
                              publish_path => 'publish/path/',# required
                              url => '');             # required
  # saves object to the DB and creates the root category '/' of the site
  # getters
  my $id = $site->site_id();                    # undef until save()
  my $path = $site->preview_path();
  my $path = $site->publish_path();
  my $url = $site->preview_url();
  my $url = $site->url();
  # setters
  $site->preview_path( $new_preview_path );
  $site->publish_path( $new_publish_path );
  $site->url( $url );
  # delete the site from the database
  # a hash of search parameters
  my %params =
  ( order_desc => 1,            # result ascend unless this flag is set
    limit => 5,                   # return 5 or less site objects
    offset => 1,                  # start counting result from the
                                  # second row
    order_by => 'url'             # sort on the 'url' field
    preview_path_like => '%bob%', # match sites with preview_path
                                  # LIKE '%bob%'
    publish_path_like => '%fred%',
    preview_url => 'preview',     # match sites where preview_url is
                                  # 'preview'
    site_id => 8,
    url_like => '' );
  # any valid object field can be appended with '_like' to perform a
  # case-insensitive sub-string match on that field in the database
  # returns an array of site objects matching criteria in %params
  my @sites = pkg('Site')->find( %params );


A site is the basic organizational unit within a Krang instance. A site may correspond to a web-site but only necessarily maps to a unique URL. Content within the site is stored within categories; see Krang::Category.

On preview, site output is written to paths under 'preview_path' and then the user is redirected to 'preview_url' - it is the same for 'publish_path' and 'url' upon publishing an asset.

This module serves as a means of adding, deleting, accessing site objects for a given Krang instance. Site objects, at present, do little other than act as a means to determine the urls and path associated with a site.

N.B - On save(), the root category for the site '/' is created.



Access to fields for this object is provided my Krang::MethodMaker. The value of fields can be obtained and set in the following fashion:

 $value = $site->field_name();
 $site->field_name( $some_value );

The available fields for a site object are:




Krang, Krang::DB