Created
February 1, 2014 01:19
-
-
Save nicomen/8746593 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); | |
our @EXPORT = qw($then); | |
sub AUTOLOAD { | |
return; | |
} | |
our $then = sub { return blessed($_[0]) ? $_[0] : bless {} }; | |
package main; | |
use v5.10; | |
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'; | |
# title | |
# No title | |
# Can't call method "text" on an undefined value at test.pl line 21. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment