Created
February 1, 2014 01:15
-
-
Save nicomen/8746564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
package Invoke::IfObject; | |
use strict; | |
use warnings FATAL => 'all'; | |
use Scalar::Util qw(blessed); | |
#use Exporter 5.57 qw(import); | |
our @EXPORT = qw($then); | |
sub AUTOLOAD { | |
return; | |
} | |
our $then = sub { return blessed($_[0]) ? $_[0] : bless {} }; | |
package main; | |
use v5.10; | |
use strict; | |
use warnings; | |
use Invoke::IfObject | |
use Mojo::DOM; | |
my $d = Mojo::DOM->new('<h1>title</h1>'); | |
say $d->find('h1')->first->text; | |
say $d->find('h2')->first->$then->text || 'No title'; | |
say $d->find('h2')->first->text || 'No title'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment