Mojo/Autobox/String.pm

filter: Statementstmt 100% 17 / 17 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 4 / 4 totaltotal 100% 30 / 30 CC 3 SCAR 4.5
CC
3
Cov
100%
dom
2.0
json
2.0
BEGIN
1.0
CRAP 1.6
« ojoBox.pm ↑ Summary Mojo/Autobox.pm »
1 package Mojo::Autobox::String;
2  
3 4 ▶use Mojo::Base -strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶sub byte_stream {
Subroutine byte_stream: called CC=1 SCAR=0.0
Pod documented
6 3 require Mojo::ByteStream;
7 3 Mojo::ByteStream->new(shift);
8 }
9  
10 4 *b = \&byte_stream;
11  
12 3 ▶sub dom {
Subroutine dom: called CC=2 SCAR=6.9
Pod documented
13 3 require Mojo::DOM;
14 3 my $dom = Mojo::DOM->new(shift);
15 3 ▶ return @_ ? $dom->find(@_) : $dom;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 2 3
16 }
17  
18 5 ▶sub json {
Subroutine json: called CC=2 SCAR=6.9
Pod documented
19 5 require Mojo::JSON;
20 5 require Mojo::JSON::Pointer;
21 5 my $data = Mojo::JSON::decode_json(shift);
22 5 ▶ return @_ ? Mojo::JSON::Pointer->new($data)->get(shift) : $data;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 3 2 5
23 }
24  
25 4 *j = \&json;
26  
27 3 ▶sub url {
Subroutine url: called CC=1 SCAR=0.0
Pod documented
28 3 require Mojo::URL;
29 3 Mojo::URL->new(shift);
30 }
31  
32 4 1;
33  
34 =head1 NAME
35  
36 Mojo::Autobox::String - Autobox string methods for Mojo::Autobox
37  
38 =head1 SYNOPSIS
39  
40 use Mojo::Autobox;
41  
42 # "Trimmed"
43 ' Trimmed '->byte_stream->trim;
44  
45 # "Text"
46 '<p>Text</p>'->dom->at('p')->text;
47  
48 # "world"
49 '{"hello": "world"}'->json->{hello};
50
51 # "anchor"
52 'http://mysite.com/path#anchor'->url->fragment;
53  
54 =head1 DESCRIPTION
55  
56 String methods for L<Mojo::Autobox>.
57  
58 =head1 METHODS
59  
60 =head2 byte_stream
61  
62 Returns an instance of L<Mojo::ByteStream>, constructed from the invocant string.
63  
64 =head2 b
65  
66 An alias for L</byte_stream>.
67  
68 =head2 dom
69  
70 Returns an instance of L<Mojo::DOM>, constructed from the invocant string.
71 Optionally takes a CSS3 selector which is passed to the L<Mojo::DOM> instance's L<find|Mojo::DOM/find> method.
72  
73 =head2 json
74  
75 Parses the invocant string as JSON using L<Mojo::JSON/decode_json> and returns the result.
76 Optionally takes a JSON pointer used to delve into the resulting structure using L<Mojo::JSON::Pointer>.
77  
78 =head2 j
79  
80 An alias for L</json>.
81  
82 =head2 url
83  
84 Returns an instance of L<Mojo::URL>, constructed from the invocant string.
85  
« ojoBox.pm ↑ Summary Mojo/Autobox.pm »