lib/App/LinkSite/Site.pm

filter: Statementstmt 100% 39 / 39 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 100% 50 / 50 CC 2 SCAR 2.0
CC
2
Cov
100%
all_links
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« lib/App/LinkSite/Social.pm ↑ Summary bin/linksite »
1 =head1 NAME
2  
3 App::LinkSite::Site
4  
5 =head1 SYNOPIS
6  
7 (You probably want to just look at the L<linksite> application.)
8  
9 =head1 DESCRIPTION
10  
11 A class to model a link site (part of App::LinkSite).
12  
13 =cut
14  
15 17 ▶use Feature::Compat::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 17 class App::LinkSite::Site {
18 17 our $VERSION = '0.2.0';
19 17 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 17 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 17 ▶ no if $] >= 5.038, 'warnings', 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 17 ▶ use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 17 field $name :reader :param;
26 17 field $handle :reader :param;
27 17 field $image :reader :param;
28 17 field $desc :reader :param;
29 17 field $og_image :reader :param;
30 17 field $site_url :reader :param;
31 17 field $text_color :reader :param = undef;
32 17 field $background_color :reader :param = undef;
33  
34 17 field $socials :reader :param = [];
35 17 field $links :reader :param = [];
36 17 field $sections :reader :param = [];
37  
38 =head1 METHODS
39  
40 =head2 has_sections
41  
42 Returns true if the site has any non-empty sections.
43  
44 =cut
45  
46 16 ▶ method has_sections {
Subroutine has_sections: called CC=1 SCAR=0.0
Pod documented
47 16 return scalar(grep { $_->has_links } $self->sections->@*) > 0;
48 }
49  
50 =head2 all_links
51  
52 Returns all links from both the links array and all sections.
53  
54 =cut
55  
56 20 ▶ method all_links {
Subroutine all_links: called CC=2 SCAR=6.9
Pod documented
57 20 my @all_links = $self->links->@*;
58 20 for my $section ($self->sections->@*) {
59 5 push @all_links, $section->links->@*;
60 }
61 20 return @all_links;
62 }
63  
64 =head2 json_ld
65  
66 Returns a JSON/LD fragment for this web site.
67  
68 =cut
69  
70 15 ▶ method json_ld {
Subroutine json_ld: called CC=1 SCAR=0.0
Pod documented
71 my $json = {
72 '@context' => 'https://schema.org',
73 '@type' => 'WebPage',
74 name => "Links page for $name ($handle)",
75 mainEntity => {
76 '@context' => 'https://schema.org',
77 '@type' => 'Person',
78 name => $self->name,
79 image => $self->image,
80 2 sameAs => [ map { $_->mk_social_link } $self->socials->@* ],
81 },
82 15 relatedLink => [ map { $_->link } $self->all_links ],
83 };
84  
85 15 return JSON->new->pretty->encode($json);
86 }
87 }
88  
89 17 1;
90  
91 =head1 AUTHOR
92  
93 Dave Cross <dave@davecross.co.uk>
94  
95 =head1 COPYRIGHT AND LICENCE
96  
97 Copyright (c) 2024, Magnum Solutions Ltd. All Rights Reserved.
98  
99 This library is free software; you can redistribute it and/or modify it
100 under the same terms as Perl itself.
101  
102 =cut
« lib/App/LinkSite/Social.pm ↑ Summary bin/linksite »