summaryrefslogtreecommitdiff
path: root/LedgerSMB.pm
blob: 99a3d994b47161f64523e230751f00b4cbd7635d (plain)
  1. =head1 NAME
  2. LedgerSMB The Base class for many LedgerSMB objects, including DBObject.
  3. =head1 SYNOPSIS
  4. This module creates a basic request handler with utility functions available
  5. in database objects (LedgerSMB::DBObject)
  6. =head1 METHODS
  7. =over
  8. =item new ()
  9. This method creates a new base request instance. It also validates the
  10. session/user credentials, as appropriate for the run mode. Finally, it sets up
  11. the database connections for the user.
  12. =item date_to_number (user => $LedgerSMB::User, date => $string);
  13. This function takes the date in the format provided and returns a numeric
  14. string in YYMMDD format. This may be moved to User in the future.
  15. =item debug (file => $path);
  16. This dumps the current object to the file if that is defined and otherwise to
  17. standard output.
  18. =item escape (string => $string);
  19. This function returns the current string escaped using %hexhex notation.
  20. =item unescape (string => $string);
  21. This function returns the $string encoded using %hexhex using ordinary notation.
  22. =item format_amount (user => $LedgerSMB::User::hash, amount => $string, precision => $integer, neg_format => (-|DRCR));
  23. The function takes a monetary amount and formats it according to the user
  24. preferences, the negative format (- or DR/CR). Note that it may move to
  25. LedgerSMB::User at some point in the future.
  26. =item parse_amount (user => $LedgerSMB::User::hash, amount => $variable);
  27. If $amount is a Bigfloat, it is returned as is. If it is a string, it is
  28. parsed according to the user preferences stored in the LedgerSMB::User object.
  29. =item is_blank (name => $string)
  30. This function returns true if $self->{$string} only consists of whitespace
  31. characters or is an empty string.
  32. =item is_run_mode ('(cli|cgi|mod_perl)')
  33. This function returns 1 if the run mode is what is specified. Otherwise
  34. returns 0.
  35. =item is_allowed_role(allowed_roles => @role_names)
  36. This function returns 1 if the user's roles include any of the roles in
  37. @role_names. Currently it returns 1 when this is not found as well but when
  38. role permissions are introduced, this will change to 0.
  39. =item num_text_rows (string => $string, cols => $number, max => $number);
  40. This function determines the likely number of rows needed to hold text in a
  41. textbox. It returns either that number or max, which ever is lower.
  42. =item merge ($hashref, keys => @list, index => $number);
  43. This command merges the $hashref into the current object. If keys are
  44. specified, only those keys are used. Otherwise all keys are merged.
  45. If an index is specified, the merged keys are given a form of
  46. "$key" . "_$index", otherwise the key is used on both sides.
  47. =item redirect (msg => $string)
  48. This function redirects to the script and argument set determined by
  49. $self->{callback}, and if this is not set, goes to an info screen and prints
  50. $msg.
  51. =item redo_rows (fields => \@list, count => $integer, [index => $string);
  52. This function is undergoing serious redesign at the moment. If index is
  53. defined, that field is used for ordering the rows. If not, runningnumber is
  54. used. Behavior is not defined when index points to a field containing
  55. non-numbers.
  56. =item set (@attrs)
  57. Copies the given key=>vars to $self. Allows for finer control of
  58. merging hashes into self.
  59. =back
  60. =head1 Copyright (C) 2006, The LedgerSMB core team.
  61. # This work contains copyrighted information from a number of sources
  62. # all used with permission.
  63. #
  64. # This file contains source code included with or based on SQL-Ledger
  65. # which is Copyright Dieter Simader and DWS Systems Inc. 2000-2005
  66. # and licensed under the GNU General Public License version 2 or, at
  67. # your option, any later version. For a full list including contact
  68. # information of contributors, maintainers, and copyright holders,
  69. # see the CONTRIBUTORS file.
  70. #
  71. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  72. # Copyright (C) 2000
  73. #
  74. # Author: DWS Systems Inc.
  75. # Web: http://www.sql-ledger.org
  76. #
  77. # Contributors: Thomas Bayen <bayen@gmx.de>
  78. # Antti Kaihola <akaihola@siba.fi>
  79. # Moritz Bunkus (tex)
  80. # Jim Rawlings <jim@your-dba.com> (DB2)
  81. #====================================================================
  82. =cut
  83. use CGI::Simple;
  84. use Math::BigFloat;
  85. use LedgerSMB::Sysconfig;
  86. use Data::Dumper;
  87. use LedgerSMB::Session;
  88. use LedgerSMB::Template;
  89. use LedgerSMB::Locale;
  90. use LedgerSMB::User;
  91. use strict;
  92. package LedgerSMB;
  93. our $VERSION = '1.2.99';
  94. sub new {
  95. my $type = shift @_;
  96. my $argstr = shift @_;
  97. my %cookie;
  98. my $self = {};
  99. $self->{version} = $VERSION;
  100. $self->{dbversion} = "1.2.0";
  101. bless $self, $type;
  102. my $query = ($argstr) ? new CGI::Simple($argstr) : new CGI::Simple;
  103. my $params = $query->Vars;
  104. $self->{VERSION} = $VERSION;
  105. $self->merge($params);
  106. if ($self->is_run_mode('cgi', 'mod_perl')) {
  107. $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
  108. my @cookies = split /;/, $ENV{HTTP_COOKIE};
  109. foreach (@cookies) {
  110. my ( $name, $value ) = split /=/, $_, 2;
  111. $cookie{$name} = $value;
  112. }
  113. }
  114. $self->{action} =~ s/\W/_/g;
  115. $self->{action} = lc $self->{action};
  116. if ( $self->{path} eq "bin/lynx" ) {
  117. $self->{menubar} = 1;
  118. # Applying the path is deprecated. Use menubar instead. CT.
  119. $self->{lynx} = 1;
  120. $self->{path} = "bin/lynx";
  121. }
  122. else {
  123. $self->{path} = "bin/mozilla";
  124. }
  125. if ( ( $self->{script} =~ m#(\.\.|\\|/)# ) ) {
  126. $self->error("Access Denied");
  127. }
  128. if (!$self->{script}) {
  129. $self->{script} = 'login.pl';
  130. }
  131. if (($self->{script} eq 'login.pl') &&
  132. ($self->{action} eq 'authenticate' || !$self->{action})){
  133. return $self;
  134. }
  135. if (!$self->{company} && $self->is_run_mode('cgi', 'mod_perl')){
  136. my $ccookie = $cookie{LedgerSMB};
  137. $ccookie =~ s/.*:([^:]*)$/$1/;
  138. $self->{company} = $ccookie;
  139. }
  140. $self->_db_init;
  141. if ($self->is_run_mode('cgi', 'mod_perl')) {
  142. #check for valid session unless this is an inital authentication
  143. #request -- CT
  144. if (!Session::session_check( $cookie{"LedgerSMB"}, $self) ) {
  145. $self->_get_password("Session Expired");
  146. exit;
  147. }
  148. $self->{_user} = LedgerSMB::User->fetch_config($self);
  149. }
  150. #my $locale = LedgerSMB::Locale->get_handle($self->{_user}->{countrycode})
  151. $self->{_locale} = LedgerSMB::Locale->get_handle('en') # temporary
  152. or $self->error(__FILE__.':'.__LINE__.": Locale not loaded: $!\n");
  153. $self->{stylesheet} = $self->{_user}->{stylesheet};
  154. return $self;
  155. }
  156. sub _get_password {
  157. my ($self) = shift @_;
  158. $self->{sessionexpired} = shift @_;
  159. $self->{hidden} = [];
  160. for (keys %$self){
  161. next if $_ =~ /(^script$|^endsession$|^password$|^hidden$)/;
  162. my $attr = {};
  163. $attr->{name} = $_;
  164. $attr->{value} = $self->{$_};
  165. push @{$self->{hidden}}, $attr;
  166. }
  167. my $template = LedgerSMB::Template->new(
  168. user =>$self->{_user},
  169. locale => $self->{_locale},
  170. path => 'UI',
  171. template => 'get_password',
  172. format => 'HTML'
  173. );
  174. $template->render($self);
  175. $template->output('http');
  176. exit;
  177. }
  178. sub debug {
  179. my $self = shift @_;
  180. my $args = shift @_;
  181. my $file;
  182. if (scalar keys %$args){
  183. $file = $args->{'file'};
  184. }
  185. my $d = Data::Dumper->new( [$self] );
  186. $d->Sortkeys(1);
  187. if ($file) {
  188. open( FH, '>', "$file" ) or die $!;
  189. print FH $d->Dump();
  190. close(FH);
  191. }
  192. else {
  193. print "\n";
  194. print $d->Dump();
  195. }
  196. }
  197. sub escape {
  198. my $self = shift;
  199. my %args = @_;
  200. my $str = $args{string};
  201. my $regex = qr/([^a-zA-Z0-9_.-])/;
  202. $str =~ s/$regex/sprintf("%%%02x", ord($1))/ge;
  203. $str;
  204. }
  205. sub is_blank {
  206. my $self = shift @_;
  207. my %args = @_;
  208. my $name = $args{name};
  209. if (not defined $name){
  210. # TODO: Raise error
  211. }
  212. my $rc;
  213. if ( $self->{$name} =~ /^\s*$/ ) {
  214. $rc = 1;
  215. }
  216. else {
  217. $rc = 0;
  218. }
  219. $rc;
  220. }
  221. sub is_run_mode {
  222. my $self = shift @_;
  223. my $mode = lc shift @_;
  224. my $rc = 0;
  225. if ( $mode eq 'cgi' && $ENV{GATEWAY_INTERFACE} ) {
  226. $rc = 1;
  227. }
  228. elsif ( $mode eq 'cli' && !( $ENV{GATEWAY_INTERFACE} || $ENV{MOD_PERL} ) ) {
  229. $rc = 1;
  230. }
  231. elsif ( $mode eq 'mod_perl' && $ENV{MOD_PERL} ) {
  232. $rc = 1;
  233. }
  234. $rc;
  235. }
  236. sub num_text_rows {
  237. my $self = shift @_;
  238. my %args = @_;
  239. my $string = $args{string};
  240. my $cols = $args{cols};
  241. my $maxrows = $args{max};
  242. my $rows = 0;
  243. for ( split /\n/, $string ) {
  244. my $line = $_;
  245. while ( length($line) > $cols ) {
  246. my $fragment = substr( $line, 0, $cols + 1 );
  247. $fragment =~ s/^(.*)\W.*$/$1/;
  248. $line =~ s/$fragment//;
  249. if ( $line eq $fragment ) { # No word breaks!
  250. $line = "";
  251. }
  252. ++$rows;
  253. }
  254. ++$rows;
  255. }
  256. if ( !defined $maxrows ) {
  257. $maxrows = $rows;
  258. }
  259. return ( $rows > $maxrows ) ? $maxrows : $rows;
  260. }
  261. sub redirect {
  262. my $self = shift @_;
  263. my %args = @_;
  264. my $msg = $args{msg};
  265. if ( $self->{callback} || !$msg ) {
  266. main::redirect();
  267. exit;
  268. }
  269. else {
  270. $self->info($msg);
  271. }
  272. }
  273. # TODO: Either we should have an amount class with formats and such attached
  274. # Or maybe we should move this into the user class...
  275. sub format_amount {
  276. # Based on SQL-Ledger's Form::format_amount
  277. my $self = shift @_;
  278. my %args = @_;
  279. my $myconfig = $args{user};
  280. my $amount = $args{amount};
  281. my $places = $args{precision};
  282. my $dash = $args{neg_format};
  283. my $negative;
  284. if ($amount) {
  285. $amount = $self->parse_amount( 'user' => $myconfig, 'amount' => $amount );
  286. $negative = ( $amount < 0 );
  287. $amount =~ s/-//;
  288. }
  289. if ( $places =~ /\d+/ ) {
  290. #$places = 4 if $places == 2;
  291. $amount = $self->round_amount( $amount, $places );
  292. }
  293. # is the amount negative
  294. # Parse $myconfig->{numberformat}
  295. my ( $ts, $ds ) = ( $1, $2 );
  296. if ($amount) {
  297. if ( $myconfig->{numberformat} ) {
  298. my ( $whole, $dec ) = split /\./, "$amount";
  299. $amount = join '', reverse split //, $whole;
  300. if ($places) {
  301. $dec .= "0" x $places;
  302. $dec = substr( $dec, 0, $places );
  303. }
  304. if ( $myconfig->{numberformat} eq '1,000.00' ) {
  305. $amount =~ s/\d{3,}?/$&,/g;
  306. $amount =~ s/,$//;
  307. $amount = join '', reverse split //, $amount;
  308. $amount .= "\.$dec" if ( $dec ne "" );
  309. }
  310. elsif ( $myconfig->{numberformat} eq '1 000.00' ) {
  311. $amount =~ s/\d{3,}?/$& /g;
  312. $amount =~ s/\s$//;
  313. $amount = join '', reverse split //, $amount;
  314. $amount .= "\.$dec" if ( $dec ne "" );
  315. }
  316. elsif ( $myconfig->{numberformat} eq "1'000.00" ) {
  317. $amount =~ s/\d{3,}?/$&'/g;
  318. $amount =~ s/'$//;
  319. $amount = join '', reverse split //, $amount;
  320. $amount .= "\.$dec" if ( $dec ne "" );
  321. }
  322. elsif ( $myconfig->{numberformat} eq '1.000,00' ) {
  323. $amount =~ s/\d{3,}?/$&./g;
  324. $amount =~ s/\.$//;
  325. $amount = join '', reverse split //, $amount;
  326. $amount .= ",$dec" if ( $dec ne "" );
  327. }
  328. elsif ( $myconfig->{numberformat} eq '1000,00' ) {
  329. $amount = "$whole";
  330. $amount .= ",$dec" if ( $dec ne "" );
  331. }
  332. elsif ( $myconfig->{numberformat} eq '1000.00' ) {
  333. $amount = "$whole";
  334. $amount .= ".$dec" if ( $dec ne "" );
  335. }
  336. if ( $dash =~ /-/ ) {
  337. $amount = ($negative) ? "($amount)" : "$amount";
  338. }
  339. elsif ( $dash =~ /DRCR/ ) {
  340. $amount = ($negative) ? "$amount DR" : "$amount CR";
  341. }
  342. else {
  343. $amount = ($negative) ? "-$amount" : "$amount";
  344. }
  345. }
  346. }
  347. else {
  348. if ( $dash eq "0" && $places ) {
  349. if ( $myconfig->{numberformat} =~ /0,00$/ ) {
  350. $amount = "0" . "," . "0" x $places;
  351. }
  352. else {
  353. $amount = "0" . "." . "0" x $places;
  354. }
  355. }
  356. else {
  357. $amount = ( $dash ne "" ) ? "$dash" : "";
  358. }
  359. }
  360. $amount;
  361. }
  362. # This should probably go to the User object too.
  363. sub parse_amount {
  364. my $self = shift @_;
  365. my %args = @_;
  366. my $myconfig = $args{user};
  367. my $amount = $args{amount};
  368. if ( $amount eq '' or ! defined $amount) {
  369. return 0;
  370. }
  371. if ( UNIVERSAL::isa( $amount, 'Math::BigFloat' ) )
  372. { # Amount may not be an object
  373. return $amount;
  374. }
  375. my $numberformat = $myconfig->{numberformat};
  376. if ( ( $numberformat eq '1.000,00' )
  377. || ( $numberformat eq '1000,00' ) )
  378. {
  379. $amount =~ s/\.//g;
  380. $amount =~ s/,/./;
  381. }
  382. elsif ( $numberformat eq '1 000.00' ) {
  383. $amount =~ s/\s//g;
  384. }
  385. elsif ( $numberformat eq "1'000.00" ) {
  386. $amount =~ s/'//g;
  387. }
  388. $amount =~ s/,//g;
  389. if ( $amount =~ s/\((\d*\.?\d*)\)/$1/ ) {
  390. $amount = $1 * -1;
  391. }
  392. elsif ( $amount =~ s/(\d*\.?\d*)\s?DR/$1/ ) {
  393. $amount = $1 * -1;
  394. }
  395. $amount =~ s/\s?CR//;
  396. $amount = new Math::BigFloat($amount);
  397. if ($amount->is_nan){
  398. $self->error("Invalid number detected during parsing");
  399. }
  400. return ( $amount * 1 );
  401. }
  402. sub round_amount {
  403. my ( $self, $amount, $places ) = @_;
  404. # These rounding rules follow from the previous implementation.
  405. # They should be changed to allow different rules for different accounts.
  406. if ($amount >= 0) {
  407. Math::BigFloat->round_mode('+inf');
  408. }
  409. else {
  410. Math::BigFloat->round_mode('-inf');
  411. }
  412. if ($places >= 0) {
  413. $amount = Math::BigFloat->new($amount)->ffround( -$places );
  414. }
  415. else {
  416. $amount = Math::BigFloat->new($amount)->ffround( -( $places - 1 ) );
  417. }
  418. $amount->precision(undef);
  419. return $amount;
  420. }
  421. sub call_procedure {
  422. my $self = shift @_;
  423. my %args = @_;
  424. my $procname = $args{procname};
  425. my @call_args;
  426. @call_args = @{ $args{args} } if defined $args{args};
  427. my $order_by = $args{order_by};
  428. my $argstr = "";
  429. my @results;
  430. $procname = $self->{dbh}->quote_identifier($procname);
  431. print STDERR join(':', @call_args) . "\n";
  432. for ( 1 .. scalar @call_args ) {
  433. $argstr .= "?, ";
  434. }
  435. $argstr =~ s/\, $//;
  436. my $query = "SELECT * FROM $procname()";
  437. if ($order_by){
  438. $query .= " ORDER BY $order_by";
  439. }
  440. $query =~ s/\(\)/($argstr)/;
  441. my $sth = $self->{dbh}->prepare($query);
  442. if (scalar @call_args){
  443. $sth->execute(@call_args);
  444. } else {
  445. $sth->execute();
  446. }
  447. my @types = @{$sth->{TYPE}};
  448. my @names = @{$sth->{NAME_lc}};
  449. while ( my $ref = $sth->fetchrow_hashref('NAME_lc') ) {
  450. for (0 .. $#names){
  451. if ($types[$_] == 3){
  452. $ref->{$names[$_]} = Math::BigFloat->new($ref->{$names[$_]});
  453. }
  454. }
  455. push @results, $ref;
  456. }
  457. @results;
  458. }
  459. # Keeping this here due to common requirements
  460. sub is_allowed_role {
  461. my $self = shift @_;
  462. my %args = @_;
  463. my @roles = @{$args{allowed_roles}};
  464. for my $role (@roles){
  465. if (scalar(grep /^$role$/, $self->{_roles})){
  466. return 1;
  467. }
  468. }
  469. return 1; # TODO change to 0 when the role system is implmented
  470. }
  471. # This should probably be moved to User too...
  472. sub date_to_number {
  473. #based on SQL-Ledger's Form::datetonum
  474. my $self = shift @_;
  475. my %args = @_;
  476. my $myconfig = $args{user};
  477. my $date = $args{date};
  478. my ( $yy, $mm, $dd );
  479. if ( $date && $date =~ /\D/ ) {
  480. if ( $date =~ /^\d{4}-\d\d-\d\d$/ ) {
  481. ( $yy, $mm, $dd ) = split /\D/, $date;
  482. } elsif ( $myconfig->{dateformat} =~ /^yy/ ) {
  483. ( $yy, $mm, $dd ) = split /\D/, $date;
  484. } elsif ( $myconfig->{dateformat} =~ /^mm/ ) {
  485. ( $mm, $dd, $yy ) = split /\D/, $date;
  486. } elsif ( $myconfig->{dateformat} =~ /^dd/ ) {
  487. ( $dd, $mm, $yy ) = split /\D/, $date;
  488. }
  489. $dd *= 1;
  490. $mm *= 1;
  491. $yy += 2000 if length $yy == 2;
  492. $dd = substr( "0$dd", -2 );
  493. $mm = substr( "0$mm", -2 );
  494. $date = "$yy$mm$dd";
  495. }
  496. $date;
  497. }
  498. # To be replaced with a generic interface to an Error class
  499. sub error {
  500. my ( $self, $msg ) = @_;
  501. if ( $ENV{GATEWAY_INTERFACE} ) {
  502. $self->{msg} = $msg;
  503. $self->{format} = "html";
  504. delete $self->{pre};
  505. print qq|Content-Type: text/html; charset=utf-8\n\n|;
  506. print "<head></head>";
  507. print
  508. qq|<body><h2 class="error">Error!</h2> <p><b>$self->{msg}</b></body>|;
  509. exit;
  510. }
  511. else {
  512. if ( $ENV{error_function} ) {
  513. &{ $ENV{error_function} }($msg);
  514. }
  515. die "Error: $msg\n";
  516. }
  517. }
  518. # Database routines used throughout
  519. sub _db_init {
  520. my $self = shift @_;
  521. my %args = @_;
  522. # Handling of HTTP Basic Auth headers
  523. my $auth = $ENV{'HTTP_AUTHORIZATION'};
  524. $auth =~ s/Basic //i; # strip out basic authentication preface
  525. $auth = MIME::Base64::decode($auth);
  526. my ($login, $password) = split(/:/, $auth);
  527. $self->{login} = $login;
  528. if (!$self->{company}){
  529. $self->{company} = $LedgerSMB::Sysconfig::default_db;
  530. }
  531. my $dbname = $self->{company};
  532. # Note that we have to request the login/password again if the db
  533. # connection fails since this probably means bad credentials are entered.
  534. # Just in case, however, I think it is a good idea to include the DBI
  535. # error string. CT
  536. $self->{dbh} = DBI->connect(
  537. "dbi:Pg:dbname=$dbname", "$login", "$password", { AutoCommit => 0 }
  538. );
  539. my $dbh = $self->{dbh};
  540. if (($self->{script} eq 'login.pl') && ($self->{action} eq
  541. 'authenticate')){
  542. return;
  543. }
  544. elsif (!$dbh){
  545. $self->_get_password;
  546. }
  547. $dbh->{pg_server_prepare} = 0;
  548. $dbh->{pg_enable_utf8} = 1;
  549. # This is the general version check
  550. my $sth = $dbh->prepare("
  551. SELECT value FROM defaults
  552. WHERE setting_key = 'version'");
  553. $sth->execute;
  554. my ($dbversion) = $sth->fetchrow_array;
  555. if ($dbversion ne $self->{dbversion}){
  556. $self->error("Database is not the expected version. Was $dbversion, expected $self->{dbversion}");
  557. }
  558. # TODO: Add date handling settings and the like.
  559. my $query = "SELECT t.extends,
  560. coalesce (t.table_name, 'custom_' || extends)
  561. || ':' || f.field_name as field_def
  562. FROM custom_table_catalog t
  563. JOIN custom_field_catalog f USING (table_id)";
  564. my $sth = $self->{dbh}->prepare($query);
  565. $sth->execute;
  566. my $ref;
  567. while ( $ref = $sth->fetchrow_hashref('NAME_lc') ) {
  568. push @{ $self->{custom_db_fields}{ $ref->{extends} } },
  569. $ref->{field_def};
  570. }
  571. }
  572. # Deprecated, only here for old code
  573. sub dberror{
  574. my $self = shift @_;
  575. $self->error(@_);
  576. }
  577. sub redo_rows {
  578. my $self = shift @_;
  579. my %args = @_;
  580. my @flds = @{ $args{fields} };
  581. my $count = $args{count};
  582. my $index = ( $args{index} ) ? $args{index} : 'runningnumber';
  583. my @rows;
  584. my $i; # incriment counter use only
  585. for $i ( 1 .. $count ) {
  586. my $temphash = { _inc => $i };
  587. for my $fld (@flds) {
  588. $temphash->{$fld} = $self->{ "$fld" . "_$i" };
  589. }
  590. push @rows, $temphash;
  591. }
  592. $i = 1;
  593. for my $row ( sort { $a->{index} <=> $b->{index} } @rows ) {
  594. for my $fld (@flds) {
  595. $self->{ "$fld" . "_$i" } = $row->{$fld};
  596. }
  597. ++$i;
  598. }
  599. }
  600. sub merge {
  601. my ( $self, $src ) = @_;
  602. for my $arg ( $self, $src ) {
  603. shift;
  604. }
  605. my %args = @_;
  606. my @keys;
  607. if (defined $args{keys}){
  608. @keys = @{ $args{keys} };
  609. }
  610. my $index = $args{index};
  611. if ( !scalar @keys ) {
  612. @keys = keys %{$src};
  613. }
  614. for my $arg ( @keys ) {
  615. my $dst_arg;
  616. if ($index) {
  617. $dst_arg = $arg . "_$index";
  618. }
  619. else {
  620. $dst_arg = $arg;
  621. }
  622. $self->{$dst_arg} = $src->{$arg};
  623. }
  624. }
  625. sub type {
  626. my $self = shift @_;
  627. if (!$ENV{REQUEST_METHOD} or
  628. ( !grep {$ENV{REQUEST_METHOD} eq $_} ("HEAD", "GET", "POST") ) ) {
  629. $self->error("Request method unset or set to unknown value");
  630. }
  631. return $ENV{REQUEST_METHOD};
  632. }
  633. sub DESTROY {}
  634. sub set {
  635. my $self = shift @_;
  636. my %args = @_;
  637. for my $arg (keys(%args)) {
  638. $self->{$arg} = $args{$arg};
  639. }
  640. return 1;
  641. }
  642. 1;