P

 view release on metacpan or  search on metacpan

lib/P.pm  view on Meta::CPAN

		no warnings 'utf8';
		print $fh ($res . (!$ctx && (!$\ || $\ ne "\n") ? "\n" : "")  );
		unsee_ret($res);
	}


	sub Pe(@) {
		my $p = ref $_[0] eq 'P' ? shift : _init_p(caller);
		unshift @_, \*STDERR;
		unshift @_, $p if ref $p;
		goto &P 
	}


	sub import { my $p = ref $_[0] eq 'P' ? $_[0] : _init_p(caller);
		my ($modname, @args) = @_;
		goto &Xporter::import if caller eq 'P';
		if (@args) {
			my @others;
			my $default = 0;
			my $got_default = 0;
			my $save_p	= [];
			my @tags = grep { 
					my $full_switch;				# has tag+args, but no colon
					if (0 == index $_, ':') {
						$_						= substr $_, 1;
						$full_switch	= $_;		# includes any '=' fields
						my ($l, $tag, $val) = (-1, $_);
						if (($l = index $_, '=') > 0) {
							$tag = substr $_, 0, $l;
							$val = substr $_, $l+1;
						}
						if ($tag eq 'default' && !$got_default) {	#can only have 1 dflt sec.
							$default = 1;
							push @$save_p, $p;
							$p = $mod_dflts{""};
						} elsif ($tag eq '--') {	#end of dflts (:--)
							$p = pop @$save_p;
							$default			= 0;
							$got_default	= 1;
						} else {
							warnings::warn P "Unrecognized flag: %s", $tag unless
								exists $mod_dflts{""}->{$tag};
							$p->{"$tag"} = defined("$val") ? "$val" : -1;
						}
					} else {
						push @others, $_;
					}
			} @args;
			@_=($modname, @others);
		}
		goto &Xporter::import;
	}




	sub ops($) { my $p = shift; my $c = ref $p || $p;
		bless $p = {};
		use Carp qw(croak);
		my $caller	= (caller)[0];
		my	$args = $_[0];
		croak "ops takes a hash to pass arguments" unless HASH $args;
		foreach (sort keys %$args) {
			if (defined $_dflts{$_}) { $p->{$_} = $args->{$_} } 
			else { 
				warn  "Unknown key \"$_\" passed to ops";} 
		}
		$p
 	}
1}

{
	package main;
	use utf8;

	unless ((caller 0)[0]) {
		binmode P::DATA, ":utf8";
		binmode *STDOUT, ":utf8";
		binmode *STDERR, ":utf8";
    $_=do{ $/=undef, <P::DATA>};
		close P::DATA;
		our @globals;
		eval $_;
    die "self-test failed: $@" if $@;
		1;
	} else {
		close P::DATA;
	}
1;
}
###########################################################################
#							Pod documentation						{{{1
#    use P;

=head1 SYNOPSIS

  use P qw[:depth=5 :undef="(undef)"];

  P FILEHANDLE FORMAT, LIST
  P FILEHANDLE, LIST         # comma is not disallowed
  P FORMAT, (LIST)
  P (LIST)
  P @ARRAY                   # may contain File Handle, Format and ARGS
	                           # all in 1 array.
  $s = P @ARRAY; P $s;       # can be same output as "P @ARRAY" 
  Pe                         # same as P STDERR,...
  $s = P FILEHANDLE ...      # sends same output to $s and FILEHANDLE

=head1 DESCRIPTION

C<P> is a combined print, printf, sprintf & say in 1 routine.  It saves
tremendously on development time.  It's not just a 1 character 'verb', 
but has other time-saving and powerful features.  It has the convenience
of C<say> in adding a newline when needed but also allows specifying
a File Handle and format statement.
C<P> accepts a filehandle with or without a comma after the filehandle.

=over

=item  o B<No more switching between print, printf, sprintf, and say.>



( run in 1.819 second using v1.01-cache-2.11-cpan-e1769b4cff6 )