PApp

 view release on metacpan or  search on metacpan

PApp/Env.pm  view on Meta::CPAN


use PApp::Config qw(DBH $DBH); DBH;
use PApp::SQL;
use PApp::Exception;

use Compress::LZF ();

use base Exporter;

$VERSION = 2.4;
@EXPORT = qw(setenv getenv unsetenv modifyenv lockenv listenv);

=item setenv key => value

Sets a single environment variable to the specified value. (mysql-specific ;)

=cut

sub setenv($$) {
   sql_exec $DBH, "replace into env (name, value) values (?, ?)",
            $_[0], Compress::LZF::sfreeze_cr $_[1];
}

=item unsetenv key

Unsets (removes) the specified environment variable.

=cut

sub unsetenv($) {
   my $key = shift;
   sql_exec $DBH, "delete from env where name = ?", $key;
}

=item getenv key

Return the value of the specified environment value

=cut

PApp/Env.pm  view on Meta::CPAN

the BLOCK returned.

=cut

sub modifyenv(&$) {
   my ($code, $key) = @_;
   my $res;
   lockenv {
      my $val = getenv $key;
      $res = $code->($val);
      setenv $key, $val;
   };
   $res;
}

=item @list = listenv

Returns a list of all environment variables (names).

=cut

PApp/Env.pm  view on Meta::CPAN

}

1;

=back

=head1 BUGS

 - should also support a tied hash interface.

 - setenv requires mysql (actually the replace sql command), but it's so
   much easier & faster that way.

=head1 SEE ALSO

L<PApp>.

=head1 AUTHOR

 Marc Lehmann <schmorp@schmorp.de>
 http://home.schmorp.de/

PApp/Log.pm  view on Meta::CPAN

   $dec .= <<'EOF';
         }
      }
EOF

   $dec = eval $dec;
   die if $@;
   $dec->();
   $st->finish;

   setenv PAPP_LASTLOG, $upto;
}

1;

=back

=head1 SEE ALSO

L<PApp>.

bin/papp-env  view on Meta::CPAN

               $eval = 1;
            },
            "<>" => sub {
               if ($_[0] =~ /^([^=]+)=(.*)$/s) {
                  my ($var, $val) = ($1, $2);
                  if ($eval) {
                     my $_val = $val;
                     $val = eval $_val;
                     die "$var=$_val: $@\n" if $@;
                  }
                  setenv $var, $val;
               } elsif ($unset) {
                  unsetenv $_[0];
               } else {
                  printval getenv $_[0];
               }
            },

   );
} else {
   for (listenv) {
      print "$_=";
      printval getenv($_);

doc/pws2001.sdf  view on Meta::CPAN


!block perl
 <macro name="tinychat*()"><pxml><![CDATA[
 #if $A{tinychat_submit} && $P{input} && !reload_p
 <:
    lockenv {
       my $r = getenv "TINYCHAT";
       shift @$r while @$r > 5;
       push @$r, escape_html sprintf "%s: %s",
                    username || "<ANON$userid>", $P{input};
       setenv "TINYCHAT", $r;
    }; 
 :> 
 #endif
 <: 
    my $r = getenv "TINYCHAT";
    echo map "<tt>$_</tt><br />", @$r;
 :>
 <br />
 <?sform -tinychat_submit => 1:>__"Chat: "<?textfield "input":><?endform:>
 ]]></pxml></macro>

doc/pws2001.sdf  view on Meta::CPAN

Nun zum Teil, der die Eingabezeile nach dem Abschicken hinzufügt:

!block perl
 #if $A{tinychat_submit} && $P{input} && !reload_p
 <:
    lockenv {
       my $r = getenv "TINYCHAT";
       shift @$r while @$r > 5;
       push @$r, escape_html sprintf "%s (%s): %s",
                    username || "<ANON$userid>", $P{input};
       setenv "TINYCHAT", $r;
    }; 
 :> 
 #endif
!endblock

Die erste Zeile testet drei Dinge:

^ Es muss "unser" Formular sein; das erkennt man daran, dass der Parameter
  C<tinychat_submit> logisch wahr ist.
& Die Eingabe sollte nicht leer sein (o.k. "0" ist auch nicht erlaubt).



( run in 1.991 second using v1.01-cache-2.11-cpan-6aa56a78535 )