catalyst2 community forums  

Go Back   catalyst2 community forums > Support > Scripting Support

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 29-06-2007, 01:28 PM   #1 (permalink)
Registered User
 
Join Date: Jun 2007
Posts: 2
Can't locate object method "new" via package "CGI"

Hello, I am attempting to run an example script but keep getting this error:

Can't locate object method "new" via package "CGI"

here is the code, does anyone know why I an reciving this error?

I am using a linux hosting package.

Code:
#!/usr/local/bin/perl

use CGI::Carp qw(fatalsToBrowser);
$cgiobject=new CGI;
$cgiobject->use_named_parameters;

@allparams=$cgiobject->param();
if ($#allparams>-1)
 {&get_state_variables} 
else 
 {&init} 

if ($orderComplete)
 { &complete_order }
else 
 { &build_order }

sub build_order()
 #build the pizza order
 { unless ($newOrderFlag)
    { $greeting="Welcome! Please begin building your pizza order." }
   else
    { $greeting="<H3>Build-a-Pizza</H3>You may modify or finalize your order below." }
   
   $greeting.="<br>Current pizza price: <font color='red'>\$".
              sprintf("%.2f",&calcTotal())."</font>.";   
   print $cgiobject->header;
   print $cgiobject->start_html(-title=>'Build-a-Pizza',-bgcolor=>'white');
   print "<H2>$greeting</H2>";
   &output_form;
   print $cgiobject->end_html;
 }

sub init()
 #define initial values for pizza parameters
 { $name="Your name";
   $address="Where to?";
   $phone="Your phone";
   $deliver="deliver";
   $toppings="pepperoni";
   $size="large";
 }

sub get_state_variables()
 #grab any parameters which were submitted
 { $name=$cgiobject->param("order_name");
   $address=$cgiobject->param("order_address");
   $phone=$cgiobject->param("order_phone");
   $deliver=$cgiobject->param("order_deliver");
   $toppings=$cgiobject->param("order_toppings");
   $size=$cgiobject->param("order_size");
   $newOrderFlag=$cgiobject->param("newOrderFlag");
   $orderComplete=$cgiobject->param("finish")
 }
 
sub calcTotal()
 #calculate pizza cost based on current parameters
 { %sizelabels=('small'=>'small (8",$5)',
                'medium'=>'medium (12",$8)',
                'large'=>'large (16",$10)',
                'xlarge'=>'x-large (18",$12)');
   %sizeprices=('small'=>5,
                'medium'=>8,
                'large'=>10,
                'xlarge'=>12);
   %toppingsprices=('small'=>.50,
                    'medium'=>.75,
                    'large'=>1.00,
                    'xlarge'=>1.25);             
                
   $baseCost=$sizeprices{$size};
   
   @allToppings=$cgiobject->param("order_toppings");
   $toppingsCost=($#allToppings+1)*($toppingsprices{$size});
   
   
   return $baseCost+$toppingsCost;
 }                                                                

sub complete_order()
 #checkout order
 { print $cgiobject->header;
   print $cgiobject->start_html(-title=>'Thank you from Build-a-Pizza',-bgcolor=>'white');
   $invoice= "<H2>Thank you for your pizza order!</H2>".
             "<HR>Deliveries should arrive in 30-45 minutes. ".
             "Pickup orders please arrive in about 20 minutes.<BR>".
             "The following order has been sent to the kitchen:<BR>";
   
   if ($deliver eq "deliver")
    { $invoice.="<B>Delivery</B> " }
   else
    { $invoice.="<B>Pickup</B> " }
   $invoice.="Order for: $name<br>";
   if ($deliver eq "deliver")
    { $invoice.="Delivery to: $address<br>" }
   $invoice.="Order Description:<br>A <B>$size</B> pizza with the following toppings:<br>";
   @allToppings=$cgiobject->param("order_toppings");
   $invoice.="<B>".join(",",@allToppings)."</B>";
   $invoice.="<BR>TOTAL DUE: ".sprintf("%.2f",&calcTotal());
   print $invoice;
   
  ##here would be code to send invoice kitchen
  ##such as by way of email
  
  }
                                                   
sub output_form()
 #construct and output the pizza form HTML
 { $theform=$cgiobject->startform(-name=>'pizzaform',
                                  -method=>'get',
                                  -action=>'/cgi-bin/pizza.cgi');
   #create name text input field
   $theform.="Your name: ";
   $theform.=$cgiobject->textfield(-name=>'order_name',
                                   -size=>30,
                                   -default=>$name);
   
   #create phone text input field
   $theform.="<BR>Your telephone number: ";
   $theform.=$cgiobject->textfield(-name=>'order_phone',
                                   -size=>10,
                                   -default=>$phone);
   
   #create address text input field if deliver option selected
   $theform.="<BR>Deliver to address:<BR>";
   $theform.=$cgiobject->textarea(-name=>'order_address',
                                   -rows=>3,
                                   -default=>$address);
   
   #create delivery radio buttons
   $theform.="<BR>";
   $theform.=$cgiobject->radio_group(-name=>'order_deliver',
                                     -values=>["pickup","deliver"],
                                     -default=>$deliver);
                                     
   #create toppings checkboxes
   $theform.="<HR>Please select toppings from the list below:<BR>";
   $theform.="<SMALL>Note: Each topping costs .50,.75,1.00,1.25 for S,M,L,XL pizza</SMALL>";
   $theform.=$cgiobject->checkbox_group(-name=>'order_toppings',
                                        -values=>['pepperoni','sausage','meatball',
                                                  'mushroom','peppers','pineapple',
                                                  'ham','shrimp','tomato',
                                                  'onion','anchovies','liver'],
                                        -default=>$toppings,
                                        -linebreak=>'false',
                                        -columns=>3);
   
   #create size radio buttons
   $theform.="<BR>Select a pizza size: ";
   $theform.=$cgiobject->radio_group(-name=>'order_size',
                                     -values=>["small","medium","large","xlarge"],
                                     -labels=>\%sizelabels,
                                     -default=>$size);
   
   
   #create hidden field for newOrderFlag
   $theform.=$cgiobject->hidden(-name=>'newOrderFlag',-value=>'1');
   
   
   #create submit and reset buttons
   $theform.="<BR><BR>";
   $theform.=$cgiobject->submit(-name=>"calculate",
                                -label=>'Calculate');
   $theform.=$cgiobject->submit(-name=>"finish",
                                -label=>'Finish Order');
   
   $theform.=$cgiobject->endform;                                                                 
   print $theform
 }
craigus is offline   Reply With Quote
Old 29-06-2007, 02:41 PM   #2 (permalink)
Bring me your problems :p
 
paulredpath's Avatar
 
Join Date: Jan 2003
Location: /dev/ahhhhhhhhh
Posts: 3,537
Hi,

I am thing the server you are on doesn't have the CARP module installed. Whats the url to the error? (feel free to pm)
paulredpath is offline   Reply With Quote
Old 29-06-2007, 03:09 PM   #3 (permalink)
Administrator
 
WhiskyFudge's Avatar
 
Join Date: Oct 2003
Posts: 1,484
Man that code brings back memories. I used the same tutorial to teach my self perl all those years ago.
__________________
Jason Robbins
jason@catalyst2.com
WhiskyFudge is offline   Reply With Quote
Old 29-06-2007, 03:42 PM   #4 (permalink)
Registered User
 
Join Date: Jun 2007
Posts: 2
Quote:
Originally Posted by WhiskyFudge View Post
Man that code brings back memories. I used the same tutorial to teach my self perl all those years ago.
Seems like a good one, Other examples i have working, but this one wont work, seems strange.. and annoying!
craigus is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:16 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.