Devel-IPerl

 view release on metacpan or  search on metacpan

example/20150209_IPerl_display_demo.pod  view on Meta::CPAN

B<View this notebook on L<nbviewer|http://nbviewer.ipython.org/github/zmughal/zmughal-iperl-notebooks/blob/master/IPerl-demos/20150209_IPerl_display_demo.ipynb>>.

This notebook demonstrates how to use the I<rich display system> in IPerl and how it can be extended on the fly.

All data that is displayed implements a C<<< Displayable >>> role. This role requires a method called C<<< iperl_data_representations >>> that returns a HashRef of different representations of the data where the keys are the MIME type of the data (e....


  use v5.16;
  use DDP; # Data::Printer
  
  my $png_display = Devel::IPerl::Display::PNG->new( "http://www.libpng.org/pub/png/PngSuite/ccwn3p08.png" );
  
  say &p( [ keys $png_display->iperl_data_representations ] );
  
  $png_display;

=begin html

<tt><font face='fixedsys, lucida console, terminal, vga, monospace' style='line-height: 1; letter-spacing: 0; font-size: 12pt'><span style='color: gray; background: black; '>[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb...

=end html

example/20150209_IPerl_display_demo.pod  view on Meta::CPAN




Notice that I just displayed that PNG by just putting the C<<< $png_display >>> variable at the end? That's because any displayable is automatically displayed if it is at the end of a cell.

But there's a problem: I don't want to type or remember C<<< Devel::IPerl::Display::PNG >>> every time I want to load up a PNG.

Instead, you can just call the helper method C<<< IPerl->png() >>> and you'll get the same result.


  IPerl->png( "http://www.libpng.org/pub/png/PngSuite/ccwn3p08.png" );

=begin html

<p><img						src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAAYagMeiWXwAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAC4lBMVEX2sN6J/3Xk/8UN/2vq/4w1/63/McCMSZeA/9b+JjT/sTTgMv4ciP//DnRR/yPFA9PIAWz/zi3/Xq...

=end html



There are other C<<< Displayable >>>s too. For example, let's load up an C<<< <iframe> >>>.

t/data/nfo  view on Meta::CPAN

http://www.libpng.org/pub/png/PngSuite/ccwn3p08.png



( run in 0.320 second using v1.01-cache-2.11-cpan-0a6323c29d9 )