Codebase list libdata-printer-perl / upstream/1.000001
New upstream version 1.000001 gregor herrmann 3 years ago
6 changed file(s) with 114 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Data-Printer
1
2 1.0.1 2021-02-25
3 BUG FIXES:
4 - properly parse the "n" option in regexes
5 - fix unwrap of __PACKAGE__, __FILENAME__ and __LINE__
6 on caller_message (GH#156)
7 - add a single space between caller message and data when
8 caller_message_newline is false
9 - proper colorization on caller message.
10 OTHER:
11 - improve documentation on caller message behavior
12 - document caveat of printing array/hash slices (GH#152)
13 - fix broken link in documentation (GH#155)
14 - improve tip on how to make a drop-in replacement
15 to Data::Dumper (GH#154)
116
217 1.0.0 2021-02-24
318 We are really excited to finally bring to you Data::Printer 1.0.0 \o/
5252 "url" : "https://github.com/garu/Data-Printer"
5353 }
5454 },
55 "version" : "1.000000",
55 "version" : "1.000001",
5656 "x_serialization_backend" : "JSON::PP version 4.06"
5757 }
2727 bugtracker: https://github.com/garu/Data-Printer/issues/
2828 license: http://dev.perl.org/licenses/
2929 repository: https://github.com/garu/Data-Printer
30 version: '1.000000'
30 version: '1.000001'
3131 x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
1010
1111 # a regex to parse a regex. Talk about full circle :)
1212 # note: we are not validating anything, just grabbing modifiers
13 if ($val =~ m/\(\?\^?([uladxismpogce]*)(?:\-[uladxismpogce]+)?:(.*)\)/s) {
13 if ($val =~ m/\(\?\^?([uladxismnpogce]*)(?:\-[uladxismnpogce]+)?:(.*)\)/s) {
1414 my ($modifiers, $parsed_val) = ($1, $2);
1515 $string = $ddp->maybe_colorize($parsed_val, 'regex');
1616 if ($modifiers) {
752752 sub _write_label {
753753 my ($self) = @_;
754754 return '' unless $self->caller_info;
755 my @caller = caller 2;
755 my @caller = caller 1;
756756
757757 my $message = $self->caller_message;
758758
760760 $message =~ s/\b__FILENAME__\b/$caller[1]/g;
761761 $message =~ s/\b__LINE__\b/$caller[2]/g;
762762
763 return $message . ($self->caller_message_newline ? "\n" : '');
763 my $separator = $self->caller_message_newline ? "\n" : ' ';
764 $message = $self->maybe_colorize($message, 'caller_info');
765 $message = $self->caller_message_position eq 'before'
766 ? $message . $separator
767 : $separator . $message
768 ;
769 return $message;
764770 }
765771
766772 sub maybe_colorize {
967973 linebreaks. (default: 'auto')
968974
969975
976 =head2 Caller Information
977
978 Data::Printer can add an informational message to every call to C<p()> or
979 C<np()> if you enable C<caller_info>. So for example if you write:
980
981 my $var = "meep!";
982 p $var, caller_info => 1;
983
984 this will output something like:
985
986 Printing in line 2 of myapp.pl:
987 "meep!"
988
989 The following options let you customize the message and how it is displayed.
990
991 =head3 caller_info
992
993 Set this option to a true value to display a L<message|/caller_message> next
994 to the data being printed. (default: 0)
995
996 =head3 caller_message
997
998 What message to print when L<caller_info|/caller_info> is true.
999
1000 Defaults to
1001 "C<< Printing in line __LINE__ of __FILENAME__ >>".
1002
1003 If the special strings C<__LINE__>, C<__FILENAME__> or C<__PACKAGE__> are
1004 present in the message, they'll be interpolated into their according value
1005 so you can customize the message at will:
1006
1007 caller_message = "[__PACKAGE__:__LINE__]"
1008
1009 =head3 caller_message_newline
1010
1011 When true, skips a line when printing L<caller_message|/caller_message>.
1012 When false, only a single space is added between the message and the data.
1013 (default: 1)
1014
1015 =head3 caller_message_position
1016
1017 This option controls where the L<caller_message|/caller_message> will appear
1018 in relation to the code being printed. Can be set to 'before' or 'after'. A
1019 line is always skipped between the message and the data (either before or
1020 after), unless you set L<caller_message_newline|/caller_message_newline> to 0.
1021 (default: 'before')
1022
1023
9701024 =head2 General Options
9711025
9721026 =head3 arrows
9761030 should it print reference arrows. Possible values are 'all' (e.g
9771031 C<< var->{x}->[y]->[z] >>), 'first' (C<< var->{x}[y][z] >>) or 'none'
9781032 (C<< var{x}[y][z] >>). Default is 'none'.
979
980 =head3 caller_info
981
982 Set this option to a true value to display a L<message|/caller_message> next
983 to the data being printed. (default: 0)
984
985 =head3 caller_message
986
987 What message to print when L<caller_info|/caller_info> is true. Defaults to
988 "C<< Printing in line __LINE__ of __FILENAME__ >>".
989
990 =head3 caller_message_newline
991
992 When true, skips a line when printing L<caller_message|/caller_message> (default: 1)
993
994 =head3 caller_message_position
995
996 This option controls where the L<caller_message|/caller_message> will appear
997 in relation to the code being printed. Can be set to 'before' or 'after'. A
998 line is always skipped between the message and the data (either before or
999 after), unless you set L<caller_message_newline|/caller_message_newline> to 0.
1000 (default: 'before')
10011033
10021034 =head3 colored
10031035
44 use Data::Printer::Common;
55 use Data::Printer::Config;
66
7 our $VERSION = '1.000000';
7 our $VERSION = '1.000001';
88 $VERSION = eval $VERSION;
99
1010 my $rc_arguments;
688688 Notice that B<< you can do this without adding Data::Printer as a dependency >>
689689 to your project! Just write your sub and it will be called with the object to
690690 be printed and a C<$ddp> object ready for you. See
691 L<< Data::Printer::Object|/Data::Printer::Object/"Methods and Accessors for Filter Writers" >>
691 L<< Data::Printer::Object|Data::Printer::Object/"Methods and Accessors for Filter Writers" >>
692692 for how to use it to pretty-print your data.
693693
694694 Finally, if your object implements string overload or provides a method called
721721
722722 my @x;
723723 p $x[5]; # undef, but will initialize the array with 5 elements (all undef)
724
725 Slices (both array and hash) must be coerced into actual arrays (or hashes)
726 to properly shown. So if you want to print a slice, instead of doing something
727 like this:
728
729 p @somevar[1..10]; # WRONG! DON'T DO THIS!
730
731 try one of those:
732
733 my @x = @somevar[1..10]; p @x; # works!
734 p [ @somevar[1..0] ]->@*; # also works!
735 p @{[@somevar[1..0]]}; # this works too!!
724736
725737 Finally, as mentioned before, you cannot pass anonymous references on the
726738 default mode of C<< use_prototypes = 1 >>:
917929 complete drop-in replacement for Template::Plugin::Dumper so you don't even have
918930 to change your previous templates!
919931
932 =head2 Migrating from Data::Dumper to Data::Printer
933
934 If you are porting your code to use Data::Printer instead of
935 Data::Dumper, you could replace:
936
937 use Data::Dumper;
938
939 with something like:
940
941 use Data::Printer;
942 sub Dumper { np @_, colored => 1 }
943
944 this sub will accept multiple variables just like Data::Dumper.
945
920946 =head2 Unified interface for Data::Printer and other debug formatters
921947
922948 I<< (contributed by Kevin McGrath (catlgrep)) >>
923949
924 If you are porting your code to use Data::Printer instead of
925 Data::Dumper or similar, you can just replace:
926
927 use Data::Dumper;
928
929 with:
930
931 use Data::Printer alias => 'Dumper';
932
933 making sure to provide Data::Printer with the proper alias for the
934 previous dumping function.
935
936 If, however, you want a really unified approach where you can easily
937 flip between debugging outputs, use L<Any::Renderer> and its plugins,
950 If you want a really unified approach to easily flip between debugging
951 outputs, use L<Any::Renderer> and its plugins,
938952 like L<Any::Renderer::Data::Printer>.
939953
940954 =head2 Printing stack traces with arguments expanded using Data::Printer
10001014 Dotan Dimet, Eden Cardim (edenc), Elliot Shank (elliotjs), Eugen Konkov (KES777),
10011015 Fernando Corrêa (SmokeMachine), Fitz Elliott, Florian (fschlich),
10021016 Frew Schmidt (frew), GianniGi, Graham Knop (haarg), Graham Todd,
1003 Gregory J. Oschwald, grr, Håkon Hægland, Nigel Metheringham (nigelm),
1017 Gregory J. Oschwald, grr, Håkon Hægland, Iaroslav O. Kosmina (darviarush),
10041018 Ivan Bessarabov (bessarabv), J Mash, James E. Keenan (jkeenan),
10051019 Jarrod Funnell (Timbus), Jay Allen (jayallen), Jay Hannah (jhannah),
10061020 jcop, Jesse Luehrs (doy), Joel Berger (jberger),
10091023 Kip Hampton (ubu), Londran, Marcel Grünauer (hanekomu),
10101024 Marco Masetti (grubert65), Mark Fowler (Trelane), Martin J. Evans,
10111025 Matt S. Trout (mst), Maxim Vuets, Michael Conrad, Mike Doherty (doherty),
1012 Nicolas R (atoomic), Nuba Princigalli (nuba), Olaf Alders (oalders),
1013 Paul Evans (LeoNerd), Pedro Melo (melo), Philippe Bruhat (BooK),
1014 Przemysław Wesołek (jest), Rebecca Turner (iarna), Renato Cron (renatoCRON),
1015 Ricardo Signes (rjbs), Rob Hoelz (hoelzro), sawyer, Sebastian Willing (Sewi),
1016 Sergey Aleynikov (randir), Slaven Rezić, Stanislaw Pusep (syp),
1017 Stephen Thirlwall (sdt), sugyan, Tai Paul, Tatsuhiko Miyagawa (miyagawa),
1018 Thomas Sibley (tsibley), Tim Heaney (oylenshpeegul), Torsten Raudssus (Getty),
1026 Nicolas R (atoomic), Nigel Metheringham (nigelm), Nuba Princigalli (nuba),
1027 Olaf Alders (oalders), Paul Evans (LeoNerd), Pedro Melo (melo),
1028 Philippe Bruhat (BooK), Przemysław Wesołek (jest), Rebecca Turner (iarna),
1029 Renato Cron (renatoCRON), Ricardo Signes (rjbs), Rob Hoelz (hoelzro),
1030 Salve J. Nilsen (sjn), sawyer, Sebastian Willing (Sewi),
1031 Sébastien Feugère (smonff), Sergey Aleynikov (randir), Slaven Rezić,
1032 Stanislaw Pusep (syp), Stephen Thirlwall (sdt), sugyan, Tai Paul,
1033 Tatsuhiko Miyagawa (miyagawa), Thomas Sibley (tsibley),
1034 Tim Heaney (oylenshpeegul), Toby Inkster (tobyink), Torsten Raudssus (Getty),
10191035 Tokuhiro Matsuno (tokuhirom), trapd00r, Tsai Chung-Kuan, vividsnow,
10201036 Wesley Dal`Col (blabos), y, Yanick Champoux (yanick).
10211037