Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Vend 0.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew M. Wilcox authored and jonjensen committed Jan 2, 2009
1 parent 85de257 commit e8858ba
Show file tree
Hide file tree
Showing 19 changed files with 1,216 additions and 248 deletions.
47 changes: 47 additions & 0 deletions ChangeLog
@@ -1,3 +1,50 @@
Tue Mar 12 16:46:13 1996 Andrew Wilcox <awilcox@world.std.com>

* Vend/Startup.pm, setup: Version 0.3.7.

* setup: Look in program path for the Vend library.

* Vend/Swish_search.pm, Vend/Strip.pm, Vend/Attribute.pm: Initial revision

* Vend/Util.pm:
(tabbed, csv, append_to_file, field_line, append_field_data):
new functions.

* Vend/Table/Import.pm (import_csv): new function.

* Vend/Table/GDBM.pm (create):
New static method has arguments in same order as InMemory.

* Vend/Page_compiled.pm:
Move escape_to_filename(), unescape_from_filename(),
name_to_filename(), filename_to_name(), readin_page(),
page_changed_date(), file_type(), recurse_pages() to Page.pm.
(test_pages): Use page_iterate().

* Vend/Page_simple.pm:
(escape_to_filename, unescape_from_filename, name_to_filename,
readin_page):
Moved to Page.pm.
(define_placeholder): remember number of arguments to placeholder
Rename read_page() to imprint_page().
(strip_page): new function.
(substitute_placeholder): fix backslash handling.
(fill_in_placeholder): check for number of arguments.

* Vend/Page.pm:
(escape_to_filename, unescape_from_filename, name_to_filename,
filename_to_name, readin_page, page_changed_date,
follow_symbolic_links, page_iterate, recurse_pages):
Moved here from Page_simple.pm and Page_compiled.pm.

* Vend/Dispatch.pm: (dispatch):
Log new sessions to New_session_log_file if defined.
Show error messages before dump of initial session and request.

* Vend/Shopcart.pm:
(configure_fields, All_fields, Required_fields, Required_desc):
new functions.

Mon Feb 26 22:29:18 1996 Andrew Wilcox <awilcox@world.std.com>

* setup: Version 0.3.6.
Expand Down
201 changes: 201 additions & 0 deletions Vend/Attribute.pm
@@ -0,0 +1,201 @@
# Attribute.pm: product attribute class
#
# $Id: Attribute.pm,v 1.1 1996/03/12 16:22:08 amw Exp $
#
package Vend::Attribute;

# Copyright 1996 by Andrew M. Wilcox <awilcox@world.std.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

use Carp;
use strict;
use Vend::Dispatch;
use Vend::Form;
use Vend::Shopcart qw(option_list option_list_selected);
use Vend::Util qw(blank);

sub new {
my $class = shift;
my $db = shift or croak "No database specified";

my ($attribute_name, $attribute_title, $attribute_plural);

my $names = [];
my $titles = {};
my $plurals = {};
my $field = {};

while (@_) {
$attribute_name = shift @_;
$attribute_title = shift @_
or croak "Title of attribute '$attribute_name' not specified";
$attribute_plural = shift @_
or croak "Plural of attribute '$attribute_name' not specified";

push @$names, $attribute_name;
$plurals->{$attribute_name} = $attribute_plural;
$titles->{$attribute_name} = $attribute_title;
$field->{$attribute_name} = $db->field_accessor($attribute_plural);
}

my $self = {db => $db,
names => $names,
titles => $titles,
plurals => $plurals,
field => $field,
};
return bless $self, $class;
}

sub attributes {
my ($s) = @_;
my $names = $s->{'names'};
return @$names;
}

sub titles {
my ($s) = @_;
my $names = $s->{'names'};
my $titles = $s->{'titles'};

return map($titles->{$_}, @$names);
}


sub range {
my ($s, $product_code, $attr) = @_;
my $db = $s->{'db'};
my $field = $s->{'field'};

return () unless $db->record_exists($product_code);
return split(/\s*,\s*/,
&{$field->{$attr}}($product_code));
}

sub has_attribute {
my ($s, $product_code, $attr) = @_;
return ($s->range($product_code, $attr)) != 0;
}

sub catalog_choice {
my ($s, $product_code, $attribute) = @_;

my @range = $s->range($product_code, $attribute);

if (@range) {
return "<select name=$attribute>"
. option_list(@range)
. "</select>";
}
else {
return undef;
}
}

sub add_form {
my ($s, $product_code, $add_url, $button_title) = @_;
my $names = $s->{'names'};

my $r = "<form action=\"$add_url\" method=post>\n";
my ($attribute, $select);
foreach $attribute (@$names) {
$select = $s->catalog_choice($product_code, $attribute);
$r .= " $select\n" if defined $select;
}
$r .= " <input type=submit name=add value=\"$button_title\">\n";
$r .= "</form>\n";
return $r;
}

sub shoplist_choice {
my ($s, $shoplist, $attribute, $i) = @_;

my $product_code = $shoplist->[$i]{'code'};
my $current_value = $shoplist->[$i]{$attribute};
my @range = $s->range($product_code, $attribute);

if (@range) {
$current_value = $range[0] if blank($current_value);
return qq(<select name="i$i.$attribute">)
. option_list_selected($current_value, @range)
. '</select>';
}
else {
return '<br>';
}
}

sub fetch_attributes {
my ($s, $product_code, $prefix, $input) = @_;
my $attribute_names = $s->{'names'};

my $a = {};
my ($attribute, $v);
foreach $attribute (@$attribute_names) {
$v = $s->fetch_attribute($product_code, $prefix, $input, $attribute);
$a->{$attribute} = $v if defined $v;
}
return $a;
}

sub fetch_attribute {
my ($s, $product_code, $prefix, $input, $attribute) = @_;

my @range = $s->range($product_code, $attribute);
if (@range) {
my $value = get_required_field($input, $prefix . $attribute);
interaction_error("'$value' is not a valid $attribute for '$product_code'")
unless grep($_ eq $value, @range);
return $value;
}
else {
return undef;
}
}

sub handle_add_form {
my ($s, $shoplist, $name, $path, $args, $input) = @_;
my $db = $s->{'db'};

my $product_code = $args->{'product'};

interaction_error("No product code specified for add to shopping list\n")
if blank($product_code);
unless ($db->record_exists($product_code)) {
display_special_page('noproduct', $product_code);
die "Attempted to add missing product code '$product_code' to shopping list\n";
}

my $attribute_value = $s->fetch_attributes($product_code, "", $input);

my $submit;
$submit = 'add' if defined $input->{'add'};

my $item = {code => $product_code, quantity => 1, %$attribute_value};
push @$shoplist, $item;
}

sub describe {
my ($s, $product_code, $item) = @_;
my $names = $s->{'names'};
my ($name, @a);
foreach $name (@$names) {
push @a, $item->{$name} if $s->has_attribute($product_code, $name);
}
return join(', ', @a);
}

1;
35 changes: 26 additions & 9 deletions Vend/Dispatch.pm
@@ -1,6 +1,6 @@
# Dispatch.pm: dispatch URL to page or handler
#
# $Id: Dispatch.pm,v 1.11 1996/02/26 21:28:31 amw Exp $
# $Id: Dispatch.pm,v 1.12 1996/03/12 16:08:13 amw Exp $
#
package Vend::Dispatch;

Expand Down Expand Up @@ -31,12 +31,15 @@ require Vend::Http;
use Vend::Page;
use Vend::Session;
use Vend::Uneval;
use Vend::Util qw(append_field_data);

my $Config;

sub Display_errors { $Config->{'Display_errors'} }
sub Dump_request { $Config->{'Dump_request'} }
sub Page_URL { $Config->{'Page_URL'} }
sub Display_errors { $Config->{'Display_errors'} }
sub Dump_request { $Config->{'Dump_request'} }
sub New_session_log_file { $Config->{'New_session_log_file'} }
sub New_session_log_format { $Config->{'New_session_log_format'} }
sub Page_URL { $Config->{'Page_URL'} }

sub configure {
my ($class, $config) = @_;
Expand Down Expand Up @@ -164,10 +167,20 @@ sub dispatch {
$request_path = '' unless defined $request_path;
my $request_session_id = $sessionid = $args->{se};

my $host = cgi_host();
my $user = cgi_user();

if (defined $sessionid && $sessionid ne '') {
open_session($sessionid, cgi_host(), cgi_user());
open_session($sessionid, $host, $user);
} else {
new_session(cgi_host(), cgi_user());
new_session($host, $user);
if (New_session_log_file) {
append_field_data(New_session_log_file,
New_session_log_format,
scalar localtime(),
$host,
$user);
}
}

my $initial_session = Session;
Expand Down Expand Up @@ -208,8 +221,7 @@ sub dispatch {

my $report = '';
if ($problem or Dump_request) {
$report = show_date() . show_initial_session($initial_session)
. show_request($request_path, $request_session_id);
$report = show_date();
}

if ($problem) {
Expand All @@ -226,6 +238,11 @@ sub dispatch {
print $abort_message if $debug and $abort_message;
}

if ($problem or Dump_request) {
$report .= show_initial_session($initial_session)
. show_request($request_path, $request_session_id);
}

if (Dump_request and not $eval_error) {
$report .= "Final session " . session_id() . ": "
. uneval(Session) . "\n";
Expand Down Expand Up @@ -421,7 +438,7 @@ sub _display_page {

$name =~ s,^/?,/,;
$Current_page = $name;
http()->respond("text/html", read_page($name));
http()->respond("text/html", imprint_page($name));
}

sub display_special_page {
Expand Down

0 comments on commit e8858ba

Please sign in to comment.