Creating facets

This posting simply includes a short command-line program used to create facets. It is intended to allow the programmer to get their feet wet when it comes to using the MyLibrary Perl API. Assuming you already have a MyLibrary instance installed, just copy & paste the code into your favorite text editor and run it. It will first prompt you for a facet name and note. It wil then commit your input to the database. That’s all.

#!/usr/bin/perl

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

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

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

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

# 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 created:\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.