Editing facets

Here is a tiny program that can be used to edit facets. To use it you will first need a facet ID number, but you can get that from the script in the previous posting.

#!/usr/bin/perl

# require mylibrary & practice good programming
use MyLibrary::Core;
use strict;

# scope our variables
my ( $id, $facet, $name, $note, $results );

# get user input
print "Enter the ID of the facet you want to edit: "; chop ( $id = <STDIN> );

# create a facet object
$facet = MyLibrary::Facet->new( id => $id );

# sanity check
if ( ! $facet ) {

  # error
  print "There is no facet with ID $id\n";
  exit;

}

# get user input
print "Enter information about your facet.\n";
print "  Name (" . $facet->facet_name .  "): "; chop ( $name = <STDIN> );
print "  Note (" . $facet->facet_note .  "): "; chop ( $note = <STDIN> );

# re-assign the name and note to the facet
$facet->facet_name( $name );
$facet->facet_note( $note );

# save the facet to the database
$results = $facet->commit;

# check the results
if ( $results == 1 ) {

  # echo
  print "\n";
  print "The facet was successfully edited:\n";
  print "    ID - " . $facet->facet_id . "\n";
  print "  name - " . $facet->facet_name . "\n";
  print "  note - " . $facet->facet_note . "\n";
  print "\n";

}

# done
exit;

Discussion Area - Leave a Comment

You must be logged in to post a comment.